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;
}
}
}