这段代码看不懂,谁来解释下?
public class Test {
private static Logger logger = Logger.getLogger(Test.class.getName());
public static void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("1.txt");
String str = "hello world 欢迎您!";
fos.write(str.getBytes());
FileInputStream fis = new FileInputStream("1.txt");
while (fis.available() > 0) {
System.out.println((char) fis.read());
}
}
}
fos.write(str.getBytes());这句代码我已经将字符串转换为字节了,可是为什么打开1.txt时,显示的还是字符串,还有循环中的System.out.println((char) fis.read());这句代码,为什么最后的 “欢迎您”显示的时候为乱码?不要告诉我使用FileReader这个类能够正确读取文本中的内容,那个我也会使用,我想知道的是这段代码中字节和字符到底经历过了那几次转换,我需要的是这方面的解释,谢谢!