Solved

File paths

Posted on 2004-04-13
5
240 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

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

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.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

623 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