心远专栏

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  24 随笔 :: 0 文章 :: 9 评论 :: 0 Trackbacks

java读取远程文件代码:

/* filename为远程文件地址,localfinename为本地保存地址 */
    
public   void  readRomateFile(String romatefilename , String localfilename)  {
        URL urlfile;
        BufferedReader in;
        PrintWriter out;
        String content 
=   "" ;
        String inputLine;
        
try   {
            urlfile 
=   new  URL(romatefilename);
            in 
=   new  BufferedReader( new  InputStreamReader(urlfile.openStream()));
            inputLine 
=  in.readLine();
            
while  (inputLine  !=   null {
                content 
+=  inputLine ;
                inputLine 
=  in.readLine();
            }

            System.out.println(content);
            in.close();
        }
  catch  (MalformedURLException e)  {
            
//  TODO Auto-generated catch block
            e.printStackTrace();
        }
  catch  (IOException e)  {
            
//  TODO Auto-generated catch block
            e.printStackTrace();
        }


        
/*  输出到文件 */
        
try   {
            out 
=   new  PrintWriter( new  BufferedWriter( new  FileWriter(localfilename)));
            out.print(content);
            out.close();
        }
  catch  (IOException e)  {
            
//  TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

 

posted on 2006-11-13 12:49 心远 阅读(309) 评论(0)  编辑  收藏 所属分类: java

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


网站导航: