这些是Java代码。它只是“ ByteArrayOutputStream”的小测试,当我根据教学视频进行练习时,编译通过,执行结果出现乱码,不知道哪里出错了
package com.xiaoyin.otherIO;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
// Create a buffer output stream object to write data
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Create input stream objects, realize data reading, connect a txt text, which has several in both English and Chinese
FileInputStream fis = new FileInputStream("d.txt");
// Reading data
int b = -1;
while ((b = fis.read()) != -1) {
// Store all the data you read in memory
baos.write(b);
}``
// Remove all data from the buffer and convert it to a byte array
byte[] arr = baos.toByteArray();
System.out.println(new String(arr));
// Turn off the input stream
fis.close();
}
}