已经将从网上获取的图片存入到Image的对象im中
请问怎样用java实现将此图片存入本地磁盘目录(e://photos)

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【huangshua】截止到2008-07-04 15:38:27的历史汇总数据(不包括此帖):
    发帖的总数量:41                       发帖的总分数:582                      
    结贴的总数量:38                       结贴的总分数:532                      
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:3                        未结的总分数:50                       
    结贴的百分比:92.68 %               结分的百分比:91.41 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    值得尊敬
      

  2.   

    已经将从网上获取的图片存入到Image的对象im中 
    用文件对象书写就行了
    File f = new File(.....);
    OutputStream os = f.getOutputStream();
    ImageIO.write(im, "JPEG", os);  
    os.flush();
    os.close();
     
      

  3.   


    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"));
    }
    }