Solved

File paths

Posted on 2004-04-13
5
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

752 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