newfile.txt
来自「疯狂Java讲义_源码(含Java设计模式CHM」· 文本 代码 · 共 52 行
TXT
52 行
import java.io.*;
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class FileOutputStreamTest
{
public static void main(String[] args) throws IOException
{
FileInputStream fis = null;
FileOutputStream fos = null;
try
{
//创建字节输入流
fis = new FileInputStream("FileOutputStreamTest.java");
//创建字节输入流
fos = new FileOutputStream("newFile.txt");
byte[] bbuf = new byte[32];
int hasRead = 0;
//循环从输入流中取出数据
while ((hasRead = fis.read(bbuf)) > 0 )
{
//每读取一次,即写入文件输出流,读了多少,就写多少。
fos.write(bbuf , 0 , hasRead);
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
finally
{
//使用finally块来关闭文件输入流
if (fis != null)
{
fis.close();
}
//使用finally块来关闭文件输出流
if (fos != null)
{
fos.close();
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?