Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in a file

Status
Not open for further replies.

JTan

Technical User
Oct 9, 2001
73
SG
Hi all,

I am trying to read in a file into my program and the following is my codes.

When I compile and run teh program, the program just hangs there. I wonder if there is anything wrong with my codes below. Pls advise.

===========================================================
File inputFile = new File("jobfile.txt");
FileInputStream file = new FileInputStream(inputFile);
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));

StringTokenizer reader = new StringTokenizer (stdin.readLine());
 
Your code :

stdin.readLine());

reads the line from the console, line by line. So once it reads a line, as far as it is concerned, its job is done. If you were using a BufferedReader to read a file or IO, you need to have something like :

BufferedReader br = // ... instantiate
String line = "";
while ((line = br.readLine()) != null) {
System.out.println(line);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top