Basic HTML version of Foils prepared June 5 99

Foil 65 I/O with Streams

From Java Language in the Computer Science Curriculum ADMI Tutorial Duluth Minnesota -- June 3 99. by Geoffrey C. Fox


To read and write text, numbers, etc., you layer various filters on top of the basic input and output streams. These classes have additional methods to read and write data, both ascii and binary.
For example, reading lines of text from a file:
  • BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( "filename.txt" ) ) ); while (( line = in.readLine() ) != null ) { buffer.append ( line + "\n"); } in.close ( );
Buffer
Break into lines
Read bytes from file



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Jun 5 1999