public static void main(String[] args) throws IOException {
//现在我有一个Byte[]
byte[] bs = new byte[]{1,2,3,4,5};
//确定写出文件的位置
File file = new File("Test.txt");
//建立输出字节流
FileOutputStream fos = new FileOutputStream(file);
//用FileOutputStream 的write方法写入字节数组
fos.write(bs);
System.out.println("写入成功");
//为了节省IO流的开销,需要关闭
fos.close();
}
}
总结:因为你写入的是字节,所以会显示
乱码。字节流就是这样的,用于读取文件和复制任何东西。