You should use something like this. It will
write out the file line by line to stdout.
FileReader fr = new
FileReader("nameoffile.txt");
BufferedReader br = new
BufferedReader(fr);
String str = br.readLine();
while(str!=null)
{
System.out.println(str);
str=br.readLine();
}
-Jason
----- Original ----- Original Message
-----
Sent: Wednesday, October 24, 2001 4:15
PM
Subject: Unidentified subject!
I have written a simple program that reads a file and
prints the output on the stdout. i just want to know if this is the simplest
way of doing something like this in java? when it reads the character it
takes its integer value, and so to print it i have to cast it with char...
isn't that a little too much work?
import java.lang.*;
import
java.io.*;
public class ReadFile {
public static void main(String[] args)
{
String filename;
FileReader
fr;
int c;
System.out.println("Please
Enter the file you want to read");
try
{
fr = new FileReader((new
BufferedReader(new
InputStreamReader(System.in))).readLine());
} catch
(FileNotFoundException fnfe) {
System.out.println("Sorry File not Found");
return;
} catch (IOException ioe)
{
System.out.println("Error reading file
name");
return;
}
try
{
while ((c = fr.read()) != -1)
{
System.out.print((char)c);
}
} catch (IOException ioe)
{
System.out.println("Error printing
file");
return;
}
}
}
Do You Yahoo!?
Make a great connection at Yahoo! Personals.