I've successfully read from a file; proven because I wrote to a text file by copying from a file. How do I do a System.out.println of the contents of a file? Here's my code that I used to write a file and inwhich I've also attempted to output the encoded contents of my file with println. The file I read from is called farrago.txt (from sun's site). I modified it to contain two lines of text.
import java.io.*;
public class Copy {
public static void main(
String[] args) throws IOException {
File inputFile = new File("farrago.txt");
File outputFile = new File("outagain.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
{out.write(c);
System.out.println("ToString " + out.toString());
System.out.println("Read " + in.read());
System.out.println("Encoding " + in.getEncoding());
System.out.println("Can Read? " + inputFile.canRead());
System.out.println("Path " + inputFile.getPath());
System.out.println("Length " + inputFile.length());
//System.out.println("..." + getEncoding();
}
in.close();
out.close();
}
}
