import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class test2 {
public static void main(String[] args) {
try {
// 接收一个为utf-8的字符流
OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream("TXT.txt"), "utf-8");
ow.write("你好utf-8");
ow.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
@SuppressWarnings("resource")
InputStreamReader ir = new InputStreamReader(new FileInputStream("TXT.txt"), "utf-8");
char ty[] = new char[1024];
@SuppressWarnings("unused")
int len = ir.read(ty);// 吧数据存入数组中
for (char c : ty) {
System.out.print(c);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
IO流编码与解码
最新推荐文章于 2024-02-27 21:19:54 发布