lundi 26 janvier 2015

IntelliJ 14 IDEA - Can't find the correct path to a file

I am trying to test one of my classes in IntelliJ IDEA 14 through android test in the run/debug configurations. The problem that I have is that I can't seem to locate the path to a file which has stumped me for a bit.


The location of my file is under:



main/tests/res/xml/myfile.xml


And here is my source code:



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());
}
}


And here are my Log outputs ( Sorry for the formatting ):



Current sys dir: /
Current abs dir: /myfile.xml
Exists?: false
Failed to find file: /myfile.xml


Why is it that my current sys dir only a forward slash? And how would I get the full path from "/" to "myfile.xml"


Thanks.


Aucun commentaire:

Enregistrer un commentaire