冷面阎罗

低调做人&&高调做事
随笔 - 208, 文章 - 3, 评论 - 593, 引用 - 0
数据加载中……

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

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-05-15 22:29 冷面阎罗 阅读(2238) 评论(1)  编辑  收藏 所属分类: java

评论

# re: 读取远程文件,然后在指定目录下生成同样的文件  回复  更多评论   

好文章

2007-07-18 15:06 | 蛮哥♂枫

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


网站导航: