repl.it
@bikey/

Java-FileWriter-Sample

Java

No description

fork
loading
Files
  • Main.java
  • jdt.ls-java-project
  • data.txt
  • out.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
import java.io.FileWriter;
import java.io.IOException;

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

    try {
      fw = new FileWriter("./out.txt", true);

      fw.write("ABC");
      fw.write("-");
      // int rand = (int)(Math.random() * 100);
      // Integer n = new Integer(rand);
      // fw.write(n.toString());
      fw.write(String.format("%d",65));
      fw.write("\n");

      fw.flush();
    }
    catch(IOException e) { System.out.println(e); }
    finally {
      try { fw.close(); }
      catch(IOException e){ System.out.println(e); };
    }
  }
}
?