//从URL地址复制文件到本地
    public static void copyFileFromURL(String fromURL, String toFile) throws IOException
    {
        //删除上一次复制来的文件
        File prevFile = new File(toFile);
        if (prevFile.exists())
        {
            prevFile.delete();
        }        //从URL地址复制文件到本地同名文件
        URL url = new URL(fromURL);
        url.openConnection();        BufferedInputStream is = new BufferedInputStream(url.openStream());
        BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(toFile));        int b;
        while ((b = is.read()) != -1)
        {
            os.write(b);
        }        is.close();
        os.close();
    }

解决方案 »

  1.   

    to 云横秦岭:谢谢指教,但同时有几点疑问,我现在是ftp文件夹呀,如果不允许匿名访问,也就是说要通过指定的用户名和密码才能进,我想让代码自己处理,怎么办呢?还有,我访问的文件不能用read()方法来读取,因为他有若干个字段值,每个字段长度不一样,值中间用英文逗号隔开的,怎么解决呢,还有如何生成windows服务呢,请帮忙看看
        也请版主多多留意,帮个忙呀!
      

  2.   

    http://mail.czlib.net/vbb/viewthread.php?tid=320