Hey, been a long time since I've been on here. Been a long time (I'd say 8 months) since I've truly dealt with java. Before I briefly stopped with it, I never truly grasped file I/O.

so, whats the best way to implement it?

im doing a little project (for myself) which deals with everything I learned (besides applets) and Im now stuck on the I/O.

My goal is to be able to write files with several lines in them and be able to read each file seperately
*OR*
Write one file and keep adding to it and when I read it I can just scroll through it.

thanks

November 10th, 2011, 04:22 PM

helloworld922

Re: best way for I/O

Depends on your application.

What does your program do? Does it make sense to split the files up, or is having a single file advantageous?

November 10th, 2011, 07:36 PM

Junky

Re: best way for I/O

Yeah it really depends upon what you are trying to do. File IO is expensive so reading an writing to files 100 of times a minute is a bad idea. If at all possible you should try to read once and write once. Keep the contents of the file in memory and manipulate it as much as you like and then when you are done write it back to the file. However if the file is extremely large then you may run out of memory. But the principal remains: reduce the amount of IO as much as possible.

November 11th, 2011, 03:42 AM

that_guy

Re: best way for I/O

Ok, well it would only read or write once every time the program is run. The program would kind of be like a log. You know, like "this happened on this date at this time". So if it were all one file then you could scroll through all the posts, if not thenb you would have to call those files by date or what not.