将图像文件从客户端上传到服务器时发现文件未找到错误

时间:2014-10-06 05:33:00

标签: java upload filenotfoundexception

我尝试将图片文件从客户端上传到服务器,但我在服务器控制台上收到以下错误:  java.io.FileNotFoundException:/usr/share/tomcat7/imageFolder/images/download_1412168176953.jpg(没有这样的文件或目录)

执行此操作的代码如下:

 String dirName = System.getProperty("user.home") + File.separator + "imageFolder"   ;
    File theDir = new File(dirName);

    if (!theDir.exists()) {
        if (!theDir.mkdirs()) {
            if (!theDir.mkdir()) {
                System.out.println("fail to create directory " + dirName);
            }
        }
    }

    dirName += File.separator + images;
    theDir = new File(dirName);

    if (!theDir.exists()) {
        if (!theDir.mkdirs()) {
            if (!theDir.mkdir()) {
                System.out.println("fail to create directory " + dirName);
            }
        }
    }
 Long date = new Date().getTime();

        fileName = dirName + File.separator + basename + "_" + date.toString() + "." + extname;

        File f = new File(fileName);
        OutputStream outputStream = new FileOutputStream(f);
        outputStream.write(file.getBytes());
        fileList.add(fileName);

任何人都有帮助。提前致谢

0 个答案:

没有答案