posts - 4,comments - 30,trackbacks - 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-07-18 15:08 蛮哥♂枫 阅读(260) 评论(0)  编辑  收藏 所属分类: Java

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


网站导航: