|
||
|
|||
|
Hello,
I am trying to parse a 75mb .list /.txt file to the screen first then eventually to the DB if it ever works. I am trying to use Scanner and it stops readinglines after 9-10 lines and the application commences properly no crash no nothing. The file i m trying to read is 100000 line-long IMDB rating.list file. Should i do some memory management or smth? Thanks in advance. Part of my code; Java Code
...
try {
scanner.findWithinHorizon("Title", 0);
while (scanner.hasNextLine()) {
String nextLine = scanner.nextLine();
System.out.println(nextLine);
if (!isValid(nextLine)) {
continue;
}
processLine(nextLine);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
scanner.close();
}
...
//For each line i use another scanner
private void processLine(String aLine) {
lineScanner = new Scanner(aLine);
lineScanner.useDelimiter("\\s{2,}");
//process the line...
}
Last edited by helloworld922; 07-11-2009 at 09:01 PM. |
| The Following User Says Thank You to helloworld922 For This Useful Post: | ||
zort (07-11-2009) | ||
|
||||
|
Depending upon if and how you are reading the data into memory, you may also need to set the maximum JVM memory (although based upon your description this may not be the problem - you should see an OutOfMemoryException). Just add something like -Xmx512m or -Xmx1g on the command line to safeguard against memory exceptions
Last edited by copeg; 07-11-2009 at 09:41 PM. |
|
|||
|
Thank you for your quick replies. I ll try to exlain further my problem.
When i run the code for a testfile.txt, it reads all of its 90 lines. Movie title : The Shawshank Redemption Movie title : The Godfather Movie title : The Godfather: Part II Movie title : Il buono, il brutto, il cattivo. Movie title : Pulp Fiction Movie title : Schindler's List ... Movie title : Who Made the Potatoe Salad? Movie title : Who Makes Movies? BUILD SUCCESSFUL (total time: 0 seconds) If I try it with the imdb file (100000 lines), it stops reading after 10 lines. ... 0000000124 335002 8.7 Fight Club (1999) 0000000124 63810 8.7 C'era una volta il West (1968) BUILD SUCCESSFUL (total time: 0 seconds) ... And actually in certain occasions it stops reading in the middle of a long line. ... 0000000124 335002 8.7 Fight Club (1999) 0000000124 349139 8.7 The Lord of the Rings: The Fellowshi java.lang.ArrayIndexOutOfBoundsException: 1 // out of bounds occurs when it tries to process a incomplete line. ... I understand the screen printing issue. But i would understand it better if it would crash trying to print those numoerous line. I suspect it has smth to the with the file size being huge. how can i make it crash at least?
|
|
||||
|
That last exception "java.lang.ArrayIndexOutOfBoundsException" says a lot, especially if those are not being caught. There is possibly something in your processLine function that is the culprit
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Scanner vs BufferedReader? | Bill_H | File I/O & Other I/O Streams | 11 | 27-10-2009 01:44 PM |
| Reading many files using a scanner | jayjames90 | File I/O & Other I/O Streams | 2 | 22-10-2009 09:35 PM |
| Help With Scanner | jtphenom | File I/O & Other I/O Streams | 1 | 13-10-2009 01:49 AM |
| network scanner | vivek494818 | Java Networking | 0 | 18-08-2009 04:07 AM |
| How to Read a file line by line using the Scanner class | JavaPF | Java Code Snippets and Tutorials | 0 | 17-04-2009 12:34 PM |
|
100 most searched terms
Search Cloud
|
| 2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? |