Tomcat + ImageIO: Can't create cache file!
Posted on February 27th, 2014
需求是想透過 pdfbox 將上傳的 pdf 文件中的圖片擷取出來, 以作為預覽縮圖使用,
當在 main 裡試過可以後, 就嘗試把程式搬到 Struts 上, 沒想到就丟出這個 Exception
> **Can't create cache file!**
> javax.imageio.IIOException: Can't create cache file!
> at javax.imageio.ImageIO.createImageInputStream(ImageIO.java:361)
> at javax.imageio.ImageIO.read(ImageIO.java:1351)
> at javax.imageio.ImageIO.createImageInputStream(ImageIO.java:361)
> at javax.imageio.ImageIO.read(ImageIO.java:1351)
原來是當 `ImageIO` 在 Tomcat 上使用時,
程式會預設使用 ` $CATALINA_BASE/temp` 作為轉檔用的 Cache
所以要確認該資料夾存在, 且可以存取,
若沒有就會丟出上述 IIOException
####Ref:
####Ref:
[http://codeforfun.wordpress.com/2008/04/28/iioexception-cant-create-cache-file/](http://codeforfun.wordpress.com/2008/04/28/iioexception-cant-create-cache-file/)