-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo01TryCatchFileWriter.java
More file actions
41 lines (37 loc) · 1.11 KB
/
Demo01TryCatchFileWriter.java
File metadata and controls
41 lines (37 loc) · 1.11 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
package Demo13;
import java.io.FileWriter;
import java.io.IOException;
public class Demo01TryCatchFileWriter {
public static void main(String[] args) throws IOException {
/* FileWriter fw = null;
try{
fw = new FileWriter("src\\Demo13\\b.txt",true);
fw.write("\r\n");
fw.write(97);
}catch (IOException e){
System.out.println(e);
}finally {
if(fw!=null){
try {
fw.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}*/
//JDK7
/* try(FileWriter fw = new FileWriter("src\\Demo13\\b.txt",true);){
fw.write("\r\n");
fw.write(97);
}catch (IOException e){
System.out.println(e);
}*/
FileWriter fw = new FileWriter("src\\Demo13\\b.txt",true);
try(fw){
fw.write("\r\n");
fw.write(97);
}catch (IOException e){
System.out.println(e);
}
}
}