简体   繁体   English

nio.channels.FileChannel.open 抛出 NoSuchFileException

[英]nio.channels.FileChannel.open threw NoSuchFileException

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:最近它在打开文件进行写入时抛出了NoSuchFileException异常:

    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:抛出NoSuchFileException一种情况是中间路径组件不存在时:

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. CREATE 选项只创建文件,它不创建应该包含文件的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM