黑马程序员技术交流社区
标题:
使用带缓冲功能的字节流复制文件这么写怎么拷贝失败呢?
[打印本页]
作者:
15536889258
时间:
2015-10-30 14:49
标题:
使用带缓冲功能的字节流复制文件这么写怎么拷贝失败呢?
本帖最后由 15536889258 于 2015-10-30 14:51 编辑
import java.io.*;
public class Test6
{
public static void main(String[] args)
{
BufferedInputStream bufis = null;
BufferedOutputStream bufos = null;
try
{
bufis = new BufferedInputStream(new FileInputStream(
"c:\\1.jpg"));
bufos = new BufferedOutputStream(new FileOutputStream(
"c:\\2.jpg"));
int byt = 0;
while ((byt = bufis.read()) != -1)
{
bufos.write(byt);
}
}
catch (IOException e)
{
throw new RuntimeException("拷贝失败");
}
finally
{
try
{
if (bufis != null)
bufis.close();
} catch (IOException e)
{
throw new RuntimeException("读取关闭失败");
}
try
{
if (bufos != null)
bufos.close();
}
catch (IOException e)
{
throw new RuntimeException("写入关闭失败");
}
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2