如何复制一个ZIP文件到一个新的路径下啊,我用的是读字节 我编的显示的是 filenotfoundexception。万分感谢!!!!

解决方案 »

  1.   

    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("复制完毕!");
        }
    }
      

  2.   

    filenotfoundexception。
    你读的文件存在吗?
      

  3.   

    to For_suzhen(不懂装懂):存在
    to jxcfh():不行啊,显示的还是filenotfoundexception
      

  4.   

    我把你的程序复制过来,然后在F盘建了一个"系统软件"文件夹,里面建了一个src.zip,编译执行通过!明显是你文件不存在了,程序是对的.
      

  5.   

    哦,忘了说了,我验证的时候,用的是src.war,其实我是要复制一个war文件,因为觉得war就是一个zip文件,所以就这样问大家了。如果由于蔡鸟级引起的错误,还请大家理解。