62,614
社区成员
发帖
与我相关
我的任务
分享
System.out.println(System.getProperty("file.encoding"));
String str = "我";
System.out.println("===========默认==============");
byte[] b = str.getBytes();
for(int i=0;i<b.length;i++) {
System.out.println(b[i]);
}
System.out.println("===========Unicode==============");
byte[] b5 = str.getBytes("Unicode");
for(int i=0;i<b5.length;i++) {
System.out.println(b5[i]);
}
2.这两个的输出结果也不一致啊,或者如果默认编码是其他的话,会不会一样呢?
...........
txtFile = new File("3.txt");
if (txtFile.exists()) {
os = new FileOutputStream(txtFile);
osw = new OutputStreamWriter(os,"UTF-8");-----3.1
bw = new BufferedWriter(osw);
String str = "我----" + System.getProperty("line.separator") + "是一个兵";
bw.write(str);
}
...........