if (!targetFile.exists()){
targetFile.createNewFile();
}
在创建file的时候,我们可能是在一连串的文件夹下,当文件夹不存在的时候是无法创建文件的:
File targetFile = new File(videoFramesPath+File.separator + dir + File.separator + UUID.randomUUID().toString() + ".jpg");
解决:
在创建文件之前先判断文件夹是否存在,
if (!targetFile.getParentFile().exists()){
targetFile.getParentFile().mkdirs();
}
if (!targetFile.exists()){
targetFile.createNewFile();
}
创建文件时,若文件处于一连串文件夹下,当文件夹不存在则无法创建文件。解决办法是在创建文件之前先判断文件夹是否存在。
3040

被折叠的 条评论
为什么被折叠?



