fileoutputstream把字符串转成字节输入进文件,为什么text.txt文件中是中文,而不是字节呢
Scanner sc = new Scanner(System.in);
FileOutputStream fos = new FileOutputStream("text.txt");
System.out.println("请输入:");
while(true) {
String line = sc.nextLine();
if("quit".equals(line))
break;
fos.write(line.getBytes());
fos.write("\r\n".getBytes());
}
fos.close();
|
|