Reading files outside Jar for MAC OS

Dear all,

I'm using the following code to read files outside the jar and it works fine under windows bt its giving me problems under MAC. Can any one see where the problem is....

Thanks

try{

URL url = FileParser.class.getResource("/images/hand.gif");

str=url.toString();

if(str.startsWith("jar:file:")){

String fn = str.substring(10);

int n = fn.indexOf("!");

if(n == -1)

n = fn.length();

fn = fn.substring(0,n);

n = fn.lastIndexOf("/");

fn = fn.substring(0,n+1);

str=fn+ur;

str=str.replaceAll("%20"," ");

}

else{

URL url2 = FileParser.class.getResource(ur);

str = url2.toString().replaceAll("%20"," ").substring(6);

}

}

catch (Exception npe){}

[1417 byte] By [Lila_harra] at [2007-10-2 0:44:08]
# 1
Sorry, I don't know Mac, but have a suggestion:What is the correct path format for reading a file on a Mac?What path is your code generating?What is the difference between them?If they are different, change what you create to what works.
A_Sailora at 2007-7-15 16:58:58 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks for the suggestion,The problem is that its actually pointing to the right place but it says it cant find the file and throws an file not found exceptionAny ideas?...
Lila_harra at 2007-7-15 16:58:58 > top of Java-index,Java Essentials,Java Programming...
# 3
That seems to be a contradiction.Do you have any code that sucessfully reads a file on a Mac?What's the difference?Is the computer correct? Does the file exist?
A_Sailora at 2007-7-15 16:58:58 > top of Java-index,Java Essentials,Java Programming...
# 4
Display the value of str=url.toString();
ChuckBinga at 2007-7-15 16:58:58 > top of Java-index,Java Essentials,Java Programming...
# 5

> URL url = FileParser.class.getResource("/images/hand.gif");

Ok, you say you want to read that resource, right?

InputStream stream = url.openStream();

Done.

Or, you could have skipped the URL part:

InputStream stream = FileParser.class.getResourceAsStream("/images/hand.gif");

Why do you think you have to actually get the "file name" of it, which might not even be a "file name" in the first place?

warnerjaa at 2007-7-15 16:58:58 > top of Java-index,Java Essentials,Java Programming...