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("http://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; } }




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章