• Post Reply Bookmark Topic Watch Topic
  • New Topic

Not Reading Entire File  RSS feed

 
Trefor Smith
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm trying to read a fairly large file into my program. The problem is that it is not reading all of the file. It stops after about 22k. Can anyone out there give me a solution to this? I am using the code:
try{
FileInputStream fileIn = new FileInputStream(f);
InputStreamReader inReader = new InputStreamReader(fileIn);
int length = (int)f.length();
BufferedReader in = new BufferedReader(inReader, length);
char file[] = new char[(char)f.length()];
System.out.println(f.length());
in.read(file);
fileIn.close();
Any help would be much appreciated - This is driving me nuts! :-)
 
Trefor Smith
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, the println statement is just debug code!
 
Trefor Smith
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just solved the problem. The way of creating the char array in the code was returning the wrong size. Changing the code asxs follows has solved the problem:
FileInputStream fileIn = new FileInputStream(f);
InputStreamReader inReader = new InputStreamReader(fileIn);
int length = (int)f.length();
BufferedReader in = new BufferedReader(inReader, length);
char file[] = new char[length];
in.read(file);
fileIn.close();
So there you go!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!