repl.it
@bikey/

Java-FileReader-Sample

Java

No description

fork
loading
Files
  • Main.java
  • jdt.ls-java-project
  • data.txt
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.io.FileReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) {
    FileReader fr = null;

    try {
      fr = new FileReader("./data.txt");

      System.out.println("---START---");

      int i = fr.read();
      while(i >= 0) {
        char c = (char)i;
        System.out.print(c);
        i = fr.read();
      }

      System.out.println("---END---");
    }
    catch(IOException e) { System.out.println(e); }
    finally {
      try { fr.close(); }
      catch(IOException e){ System.out.println(e); };
    }
  }
}
?