您的位置:程序门 -> java -> j2se / 基础类



复制一个zip文件到另一个路径?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


复制一个zip文件到另一个路径?[已结贴,结贴人:kkwm_2001]
发表于:2007-03-21 19:52:29 楼主
如何复制一个zip文件到一个新的路径下啊,我用的是读字节   我编的显示的是   filenotfoundexception。万分感谢!!!!
发表于:2007-03-21 20:20:301楼 得分:20
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( "复制完毕! ");
        }
}
发表于:2007-03-21 20:21:172楼 得分:0
源文件没找到
发表于:2007-03-21 21:20:193楼 得分:0
filenotfoundexception。
你读的文件存在吗?
发表于:2007-03-23 21:59:474楼 得分:0
to   for_suzhen(不懂装懂):存在
to   jxcfh():不行啊,显示的还是filenotfoundexception
发表于:2007-03-23 22:25:265楼 得分:0
我把你的程序复制过来,然后在f盘建了一个 "系统软件 "文件夹,里面建了一个src.zip,编译执行通过!明显是你文件不存在了,程序是对的.
发表于:2007-03-24 19:58:406楼 得分:0
哦,忘了说了,我验证的时候,用的是src.war,其实我是要复制一个war文件,因为觉得war就是一个zip文件,所以就这样问大家了。如果由于蔡鸟级引起的错误,还请大家理解。


快速检索

最新资讯
热门点击