forked from CPU-Code/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio43.java
More file actions
55 lines (48 loc) · 1.56 KB
/
Copy pathio43.java
File metadata and controls
55 lines (48 loc) · 1.56 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
55
/*
* @由于个人水平有限, 难免有些错误, 还请指点:
* @Author: cpu_code
* @Date: 2020-09-20 17:11:01
* @LastEditTime: 2020-09-20 17:23:27
* @FilePath: \java\IO\io43.java
* @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
* @Github: [https://github.com/CPU-Code](https://github.com/CPU-Code)
* @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
* @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
*/
package IO;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class io43 {
public static void main(String[] args) throws IOException {
// 定义文件路径,文件为gbk编码
String FileName = "cpucode_gbk.txt";
// 创建流对象,默认UTF8编码
InputStreamReader isr = new InputStreamReader(new FileInputStream(FileName));
// 创建流对象,指定GBK编码
InputStreamReader isr2 = new InputStreamReader(new FileInputStream(FileName), "GBK");
// 定义变量,保存字符
int read;
// 使用默认编码字符流读取,乱码
while ((read = isr.read()) != -1) {
System.out.print((char)read);
}
isr.close();
System.out.println();
// 使用指定编码字符流读取,正常解析
while ((read = isr2.read()) != -1) {
System.out.print((char)read);
}
isr2.close();
}
}
/*
3.cpucode
1.cpu
2.hello
4.java������
3.cpucode
1.cpu
2.hello
4.java最流弊
*/