您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)


Content Index

Content Page # 22

Buffered and character input streams

The class FileInputStream is fine if we want to read a file one byte at a time.

One of the most widely-used files structures in the computing industry is the ‘plain text’ file. Here each byte represents a character (letter, symbol, etc) and there are special characters to indicate the break between lines. This is the format that Windows Notepad uses, and is accepted by the Java compiler. HTML files are similar, but here some of the characters have extended meanings.

We can read a plain text file using a FileInputStream . All we have to do is read each character one byte at a time, and add it to a String. When we detect an end-of-line character, we process that line. Fortunately we don’t have to do this, as Java provides a class for it: the BufferedReader .

A BufferedReader provides a method called readLine() . Each time it is called it reads the next available line from the file into a String object.

Although straightforward in principle, using a BufferedReader has some awkward complications, as we shall see.

 

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg