复制一个ZIP文件到另一个路径?
如何复制一个ZIP文件到一个新的路径下啊,我用的是读字节 我编的显示的是 filenotfoundexception。万分感谢!!!!
------解决方案--------------------import java.io.File;
import java.io.FileInputStream;
import
java.io.FileNotFoundException;
import java.io.FileOutputStream;
import
java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFile
{
public static void main(String[] ags)
{
String srcFileName = "F:\\系统软件\\src.zip ";
String targetFileName = "F:\\系统软件\\target.zip ";
InputStream inStream = null;
try
{
inStream = new FileInputStream(srcFileName);
} catch (
FileNotFoundException e)
{
System.err.println( "读取文件[ " + srcFileName + "]发生错误 " + "\r\n "
+ e.getCause());
return;
}
File targetFile = new File(targetFileName);
OutputStream outStream = null;
try
{
targetFile.createNewFile();
outStream = new FileOutputStream(targetFile);
byte[] by = new byte[1024];
while (inStream.available() > 0)
{
inStream.read(by);
outStream.write(by);
}
} catch (
IOException e)
{
System.err.println( "创建文件[ " + targetFileName + "]发生错误 " + "\r\n "
+ e.getCause());
} finally
{
if (null != inStream)
{
try
{
inStream.close();
} catch (IOException e)
{
System.err.println(e.getCause());
}
}
if (null != outStream)
{
try
{
outStream.flush();
} catch (IOException e)
{
System.err.println(e.getCause());
}
try
{
outStream.close();
} catch (IOException e)
{
System.err.println(e.getCause());
}
}
}
System.out.println( "复制完毕! ");
}
}