Read file upside down : FileReader « File « Java Tutorial






import java.io.File;
import java.io.FileReader;

public class Main {
  public static void main(String[] args) throws Exception {
    File f = new File("hello.txt");
    FileReader fr = new FileReader(f);

    char[] c = new char[(int) f.length()];
    char[] cnew = new char[(int) f.length()];
    StringBuffer sbuf = new StringBuffer();
    fr.read(c, 0, (int) f.length());

    int len = (int) f.length();

    for (int i = 0, j = len - 1; i < len; i++, j--) {
      cnew[i] = c[j];
      sbuf.append(cnew[i]);
    }

    System.out.println(sbuf.toString());
    fr.close();

  }
}








11.30.FileReader
11.30.1.FileReader
11.30.2.Use a FileReader to display a text file.
11.30.3.Read the file one buffer at a time
11.30.4.Read file upside down
11.30.5.Loading text from a file
11.30.6.Wrap FileReader with BufferedReader