Solved

File paths

Posted on 2004-04-13
5
197 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:mayankeagle
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now