0

我想将图像上传到 basePath 位置。

String path = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path + "/";      
String filePath = basePath + "images_videos/";
String myFile = filePath + fileName.substring(fileName.lastIndexOf("/") + 1);
file = new File(myFile);

从上面的代码值 myFile ="http://localhost:8080/NRT/images_videos/107230452014-01-04news.png"

但是文件中的值="http:\localhost:8080\NRT\images_videos\107230452014-01-04news.png"

由于当我使用将文件写入位置时斜线的这种差异

fi.write(file);

我得到以下异常

java.io.FileNotFoundException: http:\localhost:8080\NRT\images_videos\107230452014-01-04news.png (The filename, directory name, or volume label syntax is incorrect)

有关如何解决此问题的任何帮助?

有关信息:上面的“filePath”将用于显示来自同一位置的图像。

4

0 回答 0