Accessing file with FileInputStream from a different directory
Hi
Could someone tell me how can I read a file say "map.txt" from a directory other than the one the project is in, please ?
my directory structure is
"Map" directory has 2 folders insise:
-> Folder1 (where is my project) and
-> Folder2 (where is "map.txt")
and I have :
FileInputStream fos = new FileInputStream("/Folder2/map.txt");
but it doesn't work
I hope you get what I mean.
cheers
[466 byte] By [
qmalqa] at [2007-11-26 17:42:36]

Relative paths only work if both you and the system agree on what the current directory is. That's why they are a bit fragile. Try this:
public class Example {
public static void main(String[] args) {
System.out.println(System.getProperty("user.dir"));
}
}
> If you are certain you are in the correct directory
> then try placing a dot in front of the path.
>
> > File f = new File("./Dir/File");
>
Remove both the dot and the initial / from the above. The initial / is the real problem here. OP is telling it to find Dir in the root directory, and he already said that it's in the Map directory. So either he has to be in Map and use Dir/File, or he has to provide a complete path to Map/Dir/File, or he has to do something with ..'s.
ejpa at 2007-7-9 0:10:48 >
