我想通過運行/調試配置中的android測試來測試我的IntelliJ IDEA 14中的一個類。我的問題是,我似乎無法找到一個文件的路徑,這個文件讓我難以理解。IntelliJ 14 IDEA - 找不到文件的正確路徑
我的文件的位置是在:
main/tests/res/xml/myfile.xml
這裏是我的源代碼:
public final void testMain() throws IOException, XmlPullParserException {
String curDir = System.getProperty("user.dir");
File file = new File(myfile.xml);
Log.d(TAG, "Current sys dir: " + curDir);
Log.d(TAG, "Current abs dir: " + file.getCanonicalPath());
Log.d(TAG, "Exists?: " + file.exists());
if (!file.exists()) {
fail("Failed to find file: " +
file.getAbsolutePath());
}
}
這裏是我的日誌輸出(很抱歉的格式):
Current sys dir:/
Current abs dir: /myfile.xml
Exists?: false
Failed to find file: /myfile.xml
爲什麼我當前的sys目錄只有一個正斜槓?而我將如何獲得從「/」到「myfile.xml」的完整路徑
謝謝。
使用類路徑!不要對目錄結構做出假設。 – 2015-01-26 23:32:08
所以我必須做新的文件(「main/tests/res/xml/myfile.xml」)? – Olva 2015-01-26 23:55:29