public class FileOutputStreamTest
{
public static void main(String[] args)
{
try (
// 创建字节输入流
var fis = new FileInputStream("FileOutputStreamTest.java");
// 创建字节输出流
var fos = new FileOutputStream("newFile.txt"))
{
var bbuf = new byte[32];
var hasRead = 0;
// 循环从输入流中取出数据
while ((hasRead = fis.read(bbuf)) > 0)
{
// 每读取一次,即写入文件输出流,读了多少,就写多少。
fos.write(bbuf, 0, hasRead);
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}