I have a microservice that is working fine most of the times. Recently it threw a NoSuchFileException
exception when it was opening a file to write:
FileChannel.open(Paths.get("/tmp/somethingirrelevant"), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
I don't understand why it can throw such exception, considering that it will create a new one if it doesn't exist.
One scenario where NoSuchFileException
is thrown is when an intermediate path component does not exist:
FileChannel.open(Paths.get("/tmp/does/not/exist"), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
The CREATE option only creates the file, it does not create the directories that should contain the file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.