阅读背景:

Java代码可自动从网络上下载文件

来源:互联网 

 
 

import java.io.BufferedInputStream;

import java.io.FileWriter; import java.net.URL; public class DownloadFromNetAddr { public static void main(String[] args) throws Exception{ boolean istag = download("https://NetAddress", "D:/111.del"); System.out.println(istag); } public static boolean download(String urlpath, String savepath){ try{ URL url = new URL(urlpath); BufferedInputStream in = new BufferedInputStream(url.openStream()); int line1; StringBuffer sb1 = new StringBuffer(); while((line1=in.read())!=-1){ sb1.append((char)line1); } String str1 = sb1.toString(); FileWriter fw = new FileWriter(savepath); fw.write(str1); fw.close(); }catch(Exception e){ return false; } return true; } } import



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: