将图片存储到本地磁盘 已经将从网上获取的图片存入到Image的对象im中请问怎样用java实现将此图片存入本地磁盘目录(e://photos) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 此回复为自动发出,仅用于显示而已,并无任何其他特殊作用楼主【huangshua】截止到2008-07-04 15:38:27的历史汇总数据(不包括此帖):发帖的总数量:41 发帖的总分数:582 结贴的总数量:38 结贴的总分数:532 无满意结贴数:0 无满意结贴分:0 未结的帖子数:3 未结的总分数:50 结贴的百分比:92.68 % 结分的百分比:91.41 % 无满意结贴率:0.00 % 无满意结分率:0.00 % 值得尊敬 已经将从网上获取的图片存入到Image的对象im中 用文件对象书写就行了File f = new File(.....);OutputStream os = f.getOutputStream();ImageIO.write(im, "JPEG", os); os.flush();os.close(); package com.dtb.users;import java.io.FileOutputStream;import java.io.InputStream;import java.io.File;import java.net.URL;public class DownLoadFile{ public static boolean downLoadFile(String source,String path){ String filename=""; if(path.indexOf(".")==-1){ filename=source.substring(source.lastIndexOf("/")+1,source.length()); if(!path.endsWith("/")) path=path+"/"; } File file=new File(path+filename); if(file.exists()){ System.out.println("has a same file in : \n"+path+filename+"\n and now it will be overwrite"); } else System.out.println("文件存放路径为:"+path+filename); try{ URL sourceurl=new URL(source); InputStream is=sourceurl.openStream(); FileOutputStream fos=new FileOutputStream(path+filename); byte[] bytes=new byte[1]; int c; while ((c=is.read(bytes))!=-1) { System.out.println("bytes[0]="+bytes[0]); fos.write(bytes,0,c); } is.close(); fos.close(); } catch(Exception e){ return false; } return true; } public static void main(String[] args){ System.out.println(downLoadFile("http://www.dajiadu.net/files/article/html/0/727/index.html","E:/temp")); }} 加了package后怎么运行 我是菜鸟,想问个想了好久的问题 新手求助 如何使用JAVA实现.Z文件的解压操作? 求<Tinking in Java>书中 例程的源代码 和 课后练习答案 再线等 JAVA初学者问题,请高手赐教! JAR,WAR,EAR三种文件有什么区别啊? JAVA线程问题,新手求教 jcreator250过期了,如何办100分送 急!查询提交后参数值的判断? 如何隐藏真实的URL? ResultSet会保留两个sql的内容还是会冲掉第一条的内容
楼主【huangshua】截止到2008-07-04 15:38:27的历史汇总数据(不包括此帖):
发帖的总数量:41 发帖的总分数:582
结贴的总数量:38 结贴的总分数:532
无满意结贴数:0 无满意结贴分:0
未结的帖子数:3 未结的总分数:50
结贴的百分比:92.68 % 结分的百分比:91.41 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
值得尊敬
用文件对象书写就行了
File f = new File(.....);
OutputStream os = f.getOutputStream();
ImageIO.write(im, "JPEG", os);
os.flush();
os.close();
package com.dtb.users;import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.File;
import java.net.URL;public class DownLoadFile{
public static boolean downLoadFile(String source,String path){
String filename="";
if(path.indexOf(".")==-1){
filename=source.substring(source.lastIndexOf("/")+1,source.length());
if(!path.endsWith("/"))
path=path+"/";
}
File file=new File(path+filename);
if(file.exists()){
System.out.println("has a same file in : \n"+path+filename+"\n and now it will be overwrite");
}
else
System.out.println("文件存放路径为:"+path+filename);
try{
URL sourceurl=new URL(source);
InputStream is=sourceurl.openStream();
FileOutputStream fos=new FileOutputStream(path+filename);
byte[] bytes=new byte[1];
int c;
while ((c=is.read(bytes))!=-1) {
System.out.println("bytes[0]="+bytes[0]);
fos.write(bytes,0,c);
}
is.close();
fos.close();
}
catch(Exception e){
return false;
}
return true;
}
public static void main(String[] args){
System.out.println(downLoadFile("http://www.dajiadu.net/files/article/html/0/727/index.html","E:/temp"));
}
}