【发布时间】:2017-10-24 15:43:29
【问题描述】:
我在使用 java 保存/创建文件时遇到问题。
java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method) ~[na:1.7.0_79]
我的环境使用的是 Linux,但安装在 Windows 上(我尝试存储文件的地方)。 每当我尝试创建文件名包含中文字符时,它都会命中。
会不会因为 Linux 和 Windows 之间的编码不同而发生这种情况?
当我尝试在类似的操作系统中运行和存储时(在 Linux 中运行应用程序,在 Linux 中存储,对于 Windows 也是如此),它运行顺利。
非常感谢任何帮助。
我用来创建文件的代码
File imgPath = new File(fullpath.toString());
if (!imgPath.exists()){
FileUtils.forceMkdir(imgPath);
imgPath.setWritable(true, false);
}
fullpath.append(File.separator).append(fileName);
outputStream = new FileOutputStream(new File(fullpath.toString()));
非常感谢。
【问题讨论】:
-
不是拼写错误,而是操作系统跨平台问题。我上面已经提到了。我在 linux 上运行我的应用程序,同时尝试将其保存在 windows mount 上。已检查路径,权限。当文件名没有中文字符时,它可以正常工作。