javax.imageio.IIOException: Can't create output stream!的解决方案

2019-03-20 11:21|来源: 网路

javax.imageio.IIOException: Can't create output stream!


解决方法:

1.ImageIO.write(image, "jpeg", response.getOutputStream());
修改为
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(response.getOutputStream());
encoder.encode(image);
就可以了。


2.为什么以前好的呢,后来查了下

I was experiencing the same "Can't create cache file" problem when using ImageIO.read() in a servlet context on Solaris UNIX. When running locally (using Tomcat) on a Win2K system, there were no problems. It seems that with the Win2K installation, the "temp" directory is automatically made. With the Solaris installation, the "temp" is not made! Simply adding the directory cured the caching problems.
So, if you have built the Tomcat be sure that the "temp" directory is created in the Tomcat root. Please let us know if it does not solves the problem.
added the temp directory, and gave "modify" permissions to the user that our Track+ is running as. Charts are now working fine.(添加temp文件夹到tomcat根目录就OK了)


转自:http://xujunxiong.iteye.com/blog/2228702

相关问答

更多
  • OpenJDK没有原生的JPEG编码器,尝试使用Sun的JDK或使用库(如JAI AFAIK,关于“粉红色色调”,Java将JPEG保存为ARGB(仍带有透明度信息)。 大多数观众在打开时假定四个频道必须对应CMYK(不是ARGB),因此也是红色。 如果将图像导入Java,透明度仍然存在。 OpenJDK does not have a native JPEG encoder, try using Sun's JDK, or using a library (such as JAI AFAIK, regar ...
  • 那是因为您没有打开文件而是打开目录。 File directory = new File(System.getProperty("user.dir") + System.getProperty("file.separator")+ "Images"; for(File file: directory.listFiles()) { BufferedImage image = ImageIO.read(file); } Well that's because you are n ...
  • 仅编码URL的主机部分,并确保使用IDN.toASCII()而不是IDN.toUnicode() String fullUrl = "http://見.香港/images/wonton.jpg"; URL url = new URL(fullUrl); url.getProtocol(); // "http" url.getHost(); // "見.香港" url.getPath(); // "/images/wonton.jpg" String asciiHost = IDN.toASCII(url ...
  • 那么,这就是为什么远程连接有不可靠的声誉。 这可能有几个原因,但最好是将这些链接视为不可靠,并定义应用程序的行为方式。 我将使用ThreadPoolExecutor并执行在后台获取图像并使用Future获取它们。 由于您经常可以通过重试来纠正它,因此运行它是一个重试几次的循环。 你可以包装这是一个类,它返回一个默认的图像,直到真实图像加载。 然后,您仍然可以决定尝试在另一个会话中重新尝试提取图像,尽管重试尝试失败。 Well, that's why remote connections have the r ...
  • 有几个工具可以用来计算Perl高尔夫。 一个是perlsecret ,它记录了许多Perl高尔夫球手使用的“秘密操作员”和技巧。 对于这个特定的代码,理解-p的作用也很重要。 它将代码封装在一堆其他代码中,然后可以用于打高尔夫球。 最后,打开Perl高尔夫球的最终工具是B :: Deparse 。 这翻译了Perl如何通过缩进等方式将代码理解为人类可读的Perl。 -p选项使B :: Deparse即使在不需要时也可以添加括号,这有助于澄清优先级。 -d选项可以更准确地表示对象。 什么对象? 观察。 $ p ...
  • 好,所以我解决了这个问题=) 从linux发行版中删除OpenJDK并手动安装oracle java 7> u25。 (好教程: http : //de.wikihow.com/Installation-von-Oracle-Java-unter-Ubuntu-Linux ) 然后我添加了一个手动加载sunToolkit的ApplicationListener(因为由于某种原因,appcontext总是空的) @SuppressWarnings("restriction") public class Con ...
  • 我拥有的源代码(Java5,但我怀疑它已经发生了很大变化)表明,如果没有注册ImageInputStream服务提供程序, createImageInputStream方法将返回null,从而获得该异常。 从ImageIO使用的IIORegistry.getDefaultInstance()上的JavaDoc: 每个ThreadGroup都会收到自己的实例; 这允许同一浏览器(例如)中的不同Applet各自拥有自己的注册表。 因此,它实际上可能是一个线程问题,因为你得到一个简单的IIORegistry新实例 ...
  • 我对你的代码做了一些改进。 我发表评论来解释这些变化: import Foundation func main() -> String { // Give more meaningful variable names let firstLine = readLine()!.components(separatedBy: " ").map{Int($0)!} let (magazineWordCount, ransomNoteWordCount) = (firstLine[0], f ...
  • 您的问题似乎是对assertz / retract的合理调用。 这些内置函数允许跟踪时间顺序,并存储任意Prolog术语,然后你可以写 :- dynamic results/2. test(a) :- a_code(Result), assertz(results(a, Result)). test(b) :- b_code(Result), assertz(results(b, Result)). test(c) :- test(a), test(b), test(a). test(c) :- tes ...
  • 在同一个项目中,这是我用于使图像显示为标签(相同位置)的代码行,并且它可以工作> charImgLabel.setIcon(new ImageIcon(new javax.swing.ImageIcon(getClass().getResource(image)).getImage().getScaledInstance(100, 100, "../images/Character.png".SCALE_SMOOTH))); 好吧,让我们暂时看看那里明显的编译器错误。 我假设该image是对当前类加载器上下 ...