...

View Full Version : File paths inconsistent after changing working directory



gizmo1650
01-02-2012, 06:22 AM
I am trying to change my working directory. To that end I created the following test program

import java.io.File;
public class foo {
public static void main(String[] args) {
System.setProperty("user.dir","/");
String foo="bar";
System.out.println((new File(foo).exists()));
foo=(new File(foo)).getAbsolutePath();
System.out.println((new File(foo)).exists());
}
}

When /bar exists, the output of this program is


false
true

When the file exists in the default working directory, and not in the new one, the output is


true
false

When it exists in neither it is


false
false

When it exists in both it is


true
true

I am modifying an already written program, and if possible would like to avoid changing every file-system call.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum