forked from Drun1baby/JavaSecurityLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileWriteUse.java
More file actions
32 lines (30 loc) · 955 Bytes
/
Copy pathFileWriteUse.java
File metadata and controls
32 lines (30 loc) · 955 Bytes
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
package src.IOStream;
import java.io.FileWriter;
import java.io.IOException;
// 使用 FileWriter 方法写入数据
public class FileWriteUse {
public static void main(String[] args) {
writeFile();
}
public static void writeFile(){
String filePath = "Serialable/src/IOStream/CreateForFile/new1.txt";
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(filePath);
char[] a = {0, 'a', ' '};
fileWriter.write("abc ");
fileWriter.write(a);
String b = "Drun1baby";
fileWriter.write(b.toCharArray());
} catch (IOException e){
e.printStackTrace();
} finally {
try{
//必须使用close()或者flush()方法,否则无法写入数据
fileWriter.close();
} catch (IOException e){
e.printStackTrace();
}
}
}
}