Bri*_*na 5 java caching servlets file-upload
我在我的网站上上传图片时遇到问题。有时,它会上传。但有时它也说can’t create cache file。我如何解决它?
这是我的代码:
File file = new File(imagePath);
BufferedImage bi;
try{
bi = ImageIO.read(file);
}catch(javax.imageio.IIOException e){
if(request.getParameter("fi") != null){
file = new File(context.getInitParameter("ImgPath") + "placeholder/150x80.png");
}else if (request.getParameter("li") != null){
file = new File(context.getInitParameter("ImgPath") + "placeholder/150x80.png");
}
bi = ImageIO.read(file);
}
OutputStream outImg = response.getOutputStream();
File cacheDir = new File(context.getInitParameter("ImgPath") + "cache");
try {
ImageIO.setCacheDirectory(cacheDir);
ImageIO.write(bi, "png", outImg);
} catch (Exception ex) {
}
outImg.close();
Run Code Online (Sandbox Code Playgroud)
问题:您的 tomcat 安装未能在启动时创建临时 文件夹或临时文件夹不可写。
解决方案:确保\temp 下存在temp 文件夹并且它是可写的。
您可以手动创建它。
或者
您可以通过在(windows) 或h (linux) 中设置环境变量的值来覆盖Tomcat 的默认临时文件夹位置。CATALINA_TMPDIRcatalina.batcatalina.s
# CATALINA_TMPDIR (Optional) Directory path location of temporary directory
# the JVM should use (java.io.tmpdir). Defaults to
# $CATALINA_BASE/temp.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4811 次 |
| 最近记录: |