-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTWrite.java
More file actions
54 lines (46 loc) · 1.13 KB
/
Copy pathTWrite.java
File metadata and controls
54 lines (46 loc) · 1.13 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
42
43
44
45
46
47
48
49
50
51
52
53
54
package io;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import org.junit.Test;
/**
* @author:chenxun
* createDate:2016年12月11日 上午10:59:59
* Theme:
* reference:
* descript:
*/
public class TWrite {
@Test
public void write() throws IOException {
File file = new File("d:/io2");
if(!file.exists()){
file.mkdirs();
}
// file = new File("d:/io2/test.txt");
// if(!file.exists()){
// file.createNewFile();
// }
FileWriter fileWriter = new FileWriter("d:/io2/test.txt");
System.out.println(fileWriter.getEncoding());
fileWriter.write("io 测试");
fileWriter.close();
}
@Test
public void read01() throws IOException {
FileReader fileReader = new FileReader("d:/io2/test.txt");
char[] b = new char[10];
@SuppressWarnings("unused")
int l;
do {
System.out.println(String.valueOf(b));
b = new char[10];
} while ((l = fileReader.read(b))!=-1);
// while ((l = fileReader.read(b))!=-1) {
// System.out.println(String.valueOf(b));
// b = new char[10];
// }
fileReader.close();
}
}