Solved

File paths

Posted on 2004-04-13
5
231 Views
Last Modified: 2010-03-31
I am trying to make it so that i can load a image file that should be in the folder of class.
ive tried getClass().getResource("2.jpg");
But it will work on windows but not on a server based Mac.
So i would like to know how to make it so it works for both, or at least what i am doing wrong.

Thanks.
0
Comment
Question by:DrunkenTigerDDD
5 Comments
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10811887
Say your class XX and image file ZZ is residing in package yy;

InputStream in = XX.getClass().getResourceAsStream("ZZ");


This would help you in reading the stream of your image file.
0
 
LVL 13

Accepted Solution

by:
Webstorm earned 125 total points
ID: 10811893
Hi DrunkenTigerDDD,

I think it should also work for Mac environment if you copied the 2.jpg file in the same folder path.
If you made an executable jar file, the image should be in the jar file too, otherwise the file can't be found.

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10811925
Try: "/2.jpg"
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10811971
>> InputStream in = XX.getClass().getResourceAsStream("ZZ");

You probably mean :
  InputStream in = XX.class.getResourceAsStream("ZZ");
Because getClass() is not static.

0
 

Author Comment

by:DrunkenTigerDDD
ID: 10829440
Hey thanks, it was because on my Mac enviornment it is sever based and i dont have access to use that method.
Thanks though

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question