I'm using the following basic function which I copied from the net to read a text file
public void read ()
{
File file = new File("/Users/MAK/Desktop/data.txt");
System.out.println("Start");
try
{
//
// Create a new Scanner object which will read the data from the
// file passed in. To check if there are more line to read from it
// we check by calling the scanner.hasNextLine() method. We then
// read line one by one till all line is read.
//
Scanner scanner = new Scanner(file);
int lineCount = 0;
if (scanner == null)
{
System.out.println("Null File");
}
else
{
System.out.println(scanner.toString());
}
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
System.out.println("Line " + lineCount +" contain : " + line);
lineCount++;
}
System.out.println("End of Try Bluck");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
System.out.println("Exception Bluck");
}
System.out.println("End");
}
}
It's working fine with medium and small size file (which contain 10 to 20 thousand line of data) However it failed to work with a file that contain 500 thousand line. I'm not getting an error (at least not seeing anyone). so what is going on? what should i do here to be able to ready such a big files?
note: I already increased the heap for 2 GB on the test machine which run Windows Server 2008 with 4 GB ram. but this didn't help much!
Please anyone can tell me what I should do here?
Update 01
The following is the output
Start
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q�\E][infinity string=\Q∞\E]
End of Try Bluck
End