Difference between revisions of "Read a Text File"

From Progzoo
Jump to: navigation, search
(Reading lines)
Line 1: Line 1:
You can open a text file and read each line.
+
{{topTenTips}}
==Reading lines==
+
<question lang="java" className="Demo" copyFile="haggis.txt">You can open a text file and read each line.<prog>
<question lang="java" className="Demo" copyFile="haggis.txt"><prog>
+
 
import java.io.BufferedReader;
 
import java.io.BufferedReader;
 
import java.io.FileReader;
 
import java.io.FileReader;

Revision as of 21:27, 31 December 2007

You can open a text file and read each line.
  • The BufferedReader represents a text file.
  • You can create BufferedReader from a

FileReader.

  • The while condition (s=fh.readLine())!=null does two

things, it assigns the string s and it checks for null.

The text file [haggis.txt] includes some lines of text.

[Font] [Default] [Show] [Resize] [History] [Profile]