gpt4 book ai didi

java.nio.file.NoSuchFileException : why nio not creating file

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:08:34 51 4
gpt4 key购买 nike

<分区>

我正在使用 java.nio.file 包并尝试使用以下代码创建文件。

private static void printReport(String filename, String str)throws Exception{

ErrorCheck ec = new ErrorCheck();
String fileName = "/var/Emails_log/"+filename;
Path filePath = Paths.get(fileName);
File file = new File(fileName);
final BufferedWriter out = Files.newBufferedWriter(filePath, StandardCharsets.UTF_8, StandardOpenOption.APPEND);

try{
final Path tmp = filePath.getParent();
if (tmp != null){ // null will be returned if the path has no parent
Files.createDirectories(tmp);
} else {
out.write(str);
out.write('\n');
}
} catch(Exception e) {
ec.errorMsg("ERROR: GSW.SendEmail.Exception =>",e);
} finally {
if (out != null) {
out.flush();
out.close();
}
}
}

这会抛出以下异常:

java.nio.file.NoSuchFileException: /var/Emails_log/GSWvalidSentAddresses.txt
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:430)
at java.nio.file.Files.newOutputStream(Files.java:170)
at java.nio.file.Files.newBufferedWriter(Files.java:2720)
at SendEmail.printReport(SendEmail.java:114) SendEmail.send(SendEmail.java:87)

我的问题是为什么没有创建文件?

请指教

感谢期待

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com