我在netbeans和eclipse中运行了完全相同的代码片段。它适用于netbeans而不是eclipse。代码是:
public void readDocument() {
String filename ="hsk1";
String baseDirectory = "c:\\er\\development\\first\\"; // This is the Eclipse directory
String documentDirectory = baseDirectory +filename+".txt";
File f = new File(documentDirectory);
String absolutePath = f.getAbsolutePath();
Boolean fileExists = f.exists();
netbeans absolutePath中的是:c:\ er \ development \ first \ hsk1.txt,fileExists为true。 (继续阅读文件就好了)
eclipse中的绝对路径为:/c:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
不知道正斜杠的来源或我应该做什么。任何见解将不胜感激。
谢谢,
克里斯