Solved

File paths

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse formatting 6 87
nextBoolean(double p) for Random class 3 40
Opening PDF on button click and fill new document 2 35
Configure a Bean in an XML file 4 31
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

813 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