groovy创建文件并将图像放入其中

时间:2014-10-09 09:44:39

标签: java groovy

嗨我收到了一个图片请求,我就这样保存了

def th = Thread.start {
   def file = new File(destinationFileName)
   file.mkdirs()
   f.transferTo(file)
}

我收到以下错误:

Exception in thread "Thread-5" java.io.FileNotFoundException: /..../5.jpg (No such file or directory)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:449)
    at org.springframework.web.multipart.commons.CommonsMultipartFile.transferTo(CommonsMultipartFile.java:133)

是否有任何理由不创建目录和文件? (我尝试从shell创建它们,它工作正常)

1 个答案:

答案 0 :(得分:0)

我会在file.createNewFile()

之后致电mkdirs()