您好我正在尝试使用弹簧数据上传文件。当我尝试上传文件时,出现异常。
我的文件上传代码是
try {
File file = new File(this.TEMPORARY_FILES_DIRECTORY, Calendar.getInstance().getTimeInMillis() + "_" + fileNameUnderscored);
writeByteArrayToFile(file, form.getFile().getBytes());
FileInputStream inputStream = new FileInputStream(file);
GridFSFile gridFSFile = gridFsTemplate.store(inputStream, "test.png");
PropertyImage img = new PropertyImage();
img.setPropertyUid(gridFSFile.getFilename());
imagesRepository.save(img);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
在哪里TEMPORARY_FILES_DIRECTORY = new File("/home/temp/");
我得到的例外是
java.io.IOException: File '/home/temp/1392807425028_file' could not be created
在调试FileUtils
课上
if (parent.mkdirs() == false) {
throw new IOException("File '" + file + "' could not be created");
}
parent.mkdirs() is false.
谁能告诉我这段代码有什么问题。