0

我正在使用java.io.File在 java 中创建一个新文件。在 Mac-Os 上,我使用的是在 windows 上运行良好但在 mac 上运行良好的相同代码。

我在用

File file = new File(path);

创建一个新文件。

在 Windows 中:我使用String path = "C:\test\1.html"; 它工作正常。

在 Mac 上:我想创建文件"/Users/pls/1.html" 但它抛出错误为

java.io.FileNotFoundException : /Users/pls/1.html (No such file or directory)

请帮忙

4

1 回答 1

1

不要手动编写分隔符,请改用系统独立文件.分隔符。

String path = File.separator+"Users"+File.separator+"pls"+File.separator+"1.html";
File file = new File(path);
于 2012-06-29T08:22:45.117 回答