if (!targetFile.exists()){
targetFile.createNewFile();
}
When creating a file, we may be in a series of folders. When the folder does not exist, we cannot create a file
File targetFile = new File(videoFramesPath+File.separator + dir + File.separator + UUID.randomUUID().toString() + ".jpg");
Solution:
judge whether the folder exists before creating the file,
if (!targetFile.getParentFile().exists()){
targetFile.getParentFile().mkdirs();
}
if (!targetFile.exists()){
targetFile.createNewFile();
}
Read More:
- Java uses the createnewfile() method to report an error
- [Solved] nacos Startup Error: java.io.IOException…
- Ambqpioexception of rabbitmq error: java.io.ioexception
- Caused by: java.io.IOException: APR error: -730053
- Shrio | java.io.IOException: Resource [classpath:shiro.ini] could not be found
- Caused by: java.io.IOException: CreateProcess error=87, The parameter is incorrect
- When Tomcat starts: IOException while loading persistent sessions: java.io.EOFException Solutions for
- Objectinputstream of IO stream reports an error (resolved)
- solve java.net.ConnectException : Connection refused:connect report errors
- Error:java.io.FileNotFoundException: Path is not a file [How to Solve]
- Does the version of idea2020.1 import mybayis jar package or report an error? Error: (4,28) Java: package org.apache.ibatis.io does not exist
- Spring AOP uses AspectJ to report an exception that ‘the reference to the bean “mypointcut” cannot be resolved’
- Cannot open include file: ‘io.h‘: No such file or directory
- unity IOException : Failed to Move File / Directory
- New Maven project– pom.xml report errors
- Keytool error: java.io.FileNotFoundException
- Notes on Java IO streaming
- Java class file operation and exception
- Using JSON to report errors
- Java in idea: warning: source release 11 needs to be resolved by target release 11