java获取远程文件并保存到本地
解决方法:
String path="https://ssl.mail.163.com/httpsEnable.gif";
String file_name= contents.substring(contents.lastIndexOf("/")+1, contents.length());//获取文件名和后缀名
URL url=new URL(path);
InputStream is=url.openStream();
String newFile = "F:/voice/"+file_name;
OutputStream os=new FileOutputStream(newFile);
byte bf[]=new byte[1024];
int length=0;
while((length=is.read(bf, 0, 1024))!=-1){
os.write(bf, 0, length);
}
is.close();
os.close();
本文链接:http://www.yayihouse.com/yayishuwu/chapter/1759