Reputation: 75
Hi I have a java class which is working fine in windows but not in Mac OSX snow leopard. I am using Eclipse on both operating systems. On Mac OSX its throwing file not found exception.
Basically I am trying to read a file using BufferedReader and FileReader and I put my file in \resources\
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class ReadFileContents {
/**
* @param args
*/
public static void main(String[] args) {
BufferedReader br = null;
String line = "";
try {
br = new BufferedReader(new FileReader("resources\\abc"));
while((line = br.readLine())!= null)
{
System.out.println("Read ::: "+line+" From File.");
}
} catch (FileNotFoundException fne) {
fne.printStackTrace();
}catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
On Mac it is giving
java.io.FileNotFoundException: resources\abc (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at java.io.FileReader.<init>(FileReader.java:41)
at ReadFileContents.main(ReadFileContents.java:18)
Do I need any special configuration in my eclipse to get this working...
Upvotes: 0
Views: 2802
Reputation: 5505
Mac uses forward slashes: "resources/abc"
. (This will actually work on Windows as well. Only the command line interpreter requires backslashes.)
Upvotes: 1