我正在使用这种方法在项目的子目录中生成一些乌龟文件.ttl
:
public static void write(int id,int depth){
try {
FileWriter fw = null;
switch (getName()){
case ("KG1"):
fw = new FileWriter("WWW/KG1/" + depth + "/" + id + ".ttl");
break;
case ("KG2"):
fw = new FileWriter("WWW/KG2/" + depth + "/" + id + ".ttl");
}
// Write something
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
但是当我将我的项目放在Java类FileWriter
中的Ubuntu中(在Windows中仍然可以正常工作)时,我遇到了这个异常:
java.io.FileNotFoundException: /WWW/KG1/2/0.ttl (No such file or directory)
我在两个操作系统上都使用eclipse Neon,但是Ubuntu对此并不满意。
这是我到目前为止尝试过的:
-
在主项目目录下的所有文件和目录中添加写权限
-
使用绝对路径而不是相对路径,方法是使用
System.getProperty("usr.dir")
,并绘制我要提供给FileWriter
的所有路径字符串,但是它不起作用。
有什么建议吗?
谢谢!