谁给个上传图片到本地文件夹的代码,要简单的 就只要上传功能  不要什么 缩略图之类的   
最好给下注释 让我学下    我用io流传了以后图片老是损坏  

解决方案 »

  1.   

    上传到服务器呢用commo-fileupload就可以本地文件复制给你个代码/**
     * 寫文件
     * 
     * @param nm
     * @param path
     * @param fileName
     */
    public static boolean writeFile(InputStream in, String path, String fileName) {
    boolean flag = false; path = Utils.formatPath(path);
    fileName = Utils.getString(fileName, null);
    OutputStream out = null; try {
    try {
    if (in != null && path != null && fileName != null) { File dir = new File(path);
    if (!dir.exists()) {
    dir.mkdirs();
    } File file = new File(path, fileName);
    out = new FileOutputStream(file); byte[] temp = new byte[1024 * 1024];
    int len = -1; while ((len = in.read(temp)) != -1) {
    out.write(temp, 0, len);
    } } else {
    throw new NullPointerException("some parameter is empty.");
    }
    } finally {
    if (out != null) {
    out.flush();
    out.close();
    }
    if (in != null) {
    in.close();
    }
    } flag = true; } catch (Exception e) {
    e.printStackTrace();
    } return flag;
    }
      

  2.   


    Utils 是哪个包里的? 我导入的两个都报错
    没有为类型 Utils 定义方法 formatPath(String)
    import org.jcp.xml.dsig.internal.dom.Utils;
      

  3.   

    http://download.csdn.net/source/1089134
    这个下载去看看吧。
      

  4.   

    smartuploa挺好用的.网站的教程多的是.超简单.