我的空间,写我所写,禅我所藏

与我一起遨游吧

 

读取远程文件,然后在指定目录下生成同样的文件

private void FileWrite(String ftp,String DXBS,String fileName,String fileExt){
        java.net.URL urlfile 
= null;
        HttpURLConnection httpUrl 
= null;

        
try {

            
// 连接指定的网络资源,获取网络输入流
            urlfile = new java.net.URL(ftp+"/"+DXBS+"/"+fileName+"."+fileExt);
            httpUrl 
= (HttpURLConnection) urlfile.openConnection();
            httpUrl.connect();
            
int bytesum = 0;
            
int byteread = 0;
            InputStream inStream 
= httpUrl.getInputStream();
            
this.mkdir("d:/ftp/"+DXBS);
            FileOutputStream fs 
= new FileOutputStream("D:/ftp/"+DXBS+"/"+fileName+"."+fileExt);
            
byte[] buffer = new byte[1444];
            
while ((byteread = inStream.read(buffer)) != -1{
                bytesum 
+= byteread;
                fs.write(buffer, 
0, byteread);
            }

        }
 catch (Exception e) {

        }
 
        
    }

    
     
private void mkdir(String mkdirName) throws Exception {

        File dirFile 
= new File(mkdirName);
        
boolean bFile = dirFile.exists();
        
if (bFile == true{
        }
 else {
            bFile 
= dirFile.mkdir();
            
if (bFile == true{
            }
 else {
                System.exit(
1);
            }

        }


    }
      大家看代码,第一个方法是读取远程的文件,生成同样的目录文件,下面的方法是生成文件夹

posted on 2007-06-25 13:39 imcb 阅读(613) 评论(1)  编辑  收藏

评论

# re: 读取远程文件,然后在指定目录下生成同样的文件 2007-09-27 19:18 yukingyee

参数还是应该说明一下  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(2)

随笔分类

随笔档案

文章档案

搜索

最新评论

阅读排行榜

评论排行榜