import java.io.*;
class fuZhi
{
public static void main(String[] args)
{
FileOutputStream fos=null;//作用整个类
FileInputStream fis=null;
try
{
fos= new FileOutputStream("D:\\1.JPEG");//复制的
fis=new FileInputStream("E:\\2.JPEG");//原文件
byte[] buf=new byte[1024];
int len =0;
while ((len=fis.read(buf))!=-1)//读取数组
{
fos.write(buf,0,len);
}
}
catch (IOException e)
{
throw new RuntimeException("复制失败");
}
finally
{
try
{
if (fis!=null)
fis.close();
}
catch (IOException e)
{
throw new RuntimeException("读取失败");
}
try
{
if (fos!=null)
fos.close();
}
catch (IOException e)
{
throw new RuntimeException("写入关闭失败");
}
}
}
}
求解
Exception in thread "main" java.lang.RuntimeException: 复制失败
at fuZhi.main(fuzhi.java:34) |
|