I'm bewildered about the results that I'm obtaining in the Logcat. I'm trying to read a file but I'm getting a FileNotFoundException. Right now I'm hardcoding the url where the file is located.
InputStream readMyFile(String fileName){
File file = new File("C:\\Users\\Alvaro\\workspaceEclipse\\ProyectA\\file.xml");
//File file = new File("C:" +File.separator +"Users" +File.separator +"Alvaro" +File.separator +"workspaceEclipse" +File.separator +"ProyectA" +File.separator +"file.xml");
System.out.println("Working Directory = " +
System.getProperty("user.dir"));
System.out.println(file.exists());
System.out.println(file.canRead());
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(file));
if (in != null) {
in.close();
}
}catch(Exception e){
System.out.println("Error opening the file. \n" +e);
}
return in;
}
I can see that the file is not found because, somehow, a "/" is inserted at the beginning of the url string:
/C:\Users\Alvaro\workspaceEclipse\ProyectA\file.xml: open failed: ENOENT (No such file or directory)
The thing is, if I use the File.separator, the output is:
/C:/Users/Alvaro/workspaceEclipse/ProyectA/file.xml: open failed: ENOENT (No such file or directory)
Does anyone have an idea what may be happening?
Other information:
- Working directory = /
- file.exists() and file.canRead() obviously return false.
- Windows 7 Home Premium.
- Eclipse Version Indigo Service Release 2
- Java version 1.6.0_37