• Post Reply Bookmark Topic Watch Topic
  • New Topic

OutOfMemoryError  RSS feed

 
Carl Pettersson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know where I screwed this up, but it seems like I did... I'm trying to read/write data from/to a .txt file, but I get a OutOfMemoryError instead. I use this code to read and write the file:

A typical output-file should look like this

I guess it continues reading the file past the end for some reason, why?
[ November 05, 2003: Message edited by: Carl Pettersson ]
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Carl Pettersson:


Just a wild guess, but did you look at the input file to make sure it had an end-of-file marker? you should flush the FileReader before closing it. You may be chopping off the output before it gets written to disk.
There's some Java API classes that could help you out. java.io.BufferedReader has a readLine() method that returns a line of a text file as a String. java.util.StringTokenizer splits a String up by a given delimiter. If you are using Java 1.4, you can use String.split() to do the same thing. Just throwin all that out there.
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Carl Pettersson:



Upon a second look, you aren't changing the value of tempIn inside that second while loop. You just keep appending that first character. There's some other interesting 'features' in your code. Good luck!
 
Carl Pettersson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooops... Seems like I forgot quite a few steps in there Probably I should re-make it. How do I use BufferedReader on a File?
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Carl Pettersson:
How do I use BufferedReader on a File?

new BufferedReader(new FileReader(aFile));
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!