Java 字节流输入然后用字符流写

上课老师说回去试一下字节流输入然后用字符流写文件还能不能打开,答案是不能

文件结构

源码

public class Main {
    public static void main(String[] args) throws IOException {
        // write your code here
        int b = 0;
        var in = new FileInputStream("src//为什么电价夜间减半.mp3");
        var out = new FileWriter("src//copy.mp3");
        while((b = in.read()) != -1) {
            out.write(b);
        }
    }
}


(左侧为原始文件,右侧为程序处理后的文件)

对比两侧文件我们可以看到有部分字符变成了其他字符但是可能信息并没有丢失

猜你喜欢

转载自www.cnblogs.com/YY666/p/11784635.html