PDA

View Full Version : Java question re: input streams?


xwdguy
04-09-2007, 02:02 PM
I want to read a file, and have this routine inside a loop; I need to know the proper way to close the loop and avoid re-initializing things I can't reinitialize.

The commands are FileInputStream, InputStreamReader and BufferedReader. Help!!!
fi1 = new FileInputStream(args[1]);
InputStreamStream(args[1]);
BufferedReader b1 = new BufferedReader(r1);

followed by a while loop that knows when I hit the file's end, then a close.

But I'm doing something wrong -- either it goes thru only on the first iteration and never reopens/rewinds, or I get IO errors before I hit the loop a second time.
I'm looking for an answer, not a suggestion of where to look.

Geraldine L
04-09-2007, 02:48 PM
first you need to decide the loop is a finite loop or an infinite loop. To avoid reinitializing stuff, i think you need a boolean flag. if this flag is true(maybe that file is being read), break the loop. Maybe a while loop is my choice else continue to loop and reinitialise stuff. For actual codes, you have to do a bit of homework yourself. Go to www.sun.com