R
Rhino
I am working on a program that will get icon files from a jar. I have the
code to get and read those files working satisfactorily except for one
thing: if the file name (of the image file, as opposed to the file name of
the jar) contains an imbedded blank, my reading logic fails.
For example, if the jar is called My.jar and the icon file I want is called
Foo.gif, everything works fine. But if the icon file is called Foo Bar.gif,
my logic fails. I would like my code to work even if embedded blanks occur
in the file name but I'm not sure how to accomplish it. I've googled but
haven't found anything that solves the problem.
Here is the relevant fragment of my code:
try {
URL url = this.getClass().getResource( gifName );
if ( url == null ) {
System.err.println("File " + gifName + " not found.");
}
Image image =
Toolkit.getDefaultToolkit().createImage((ImageProducer) url.getContent() );
// wait till it is loaded
MediaTracker tracker;
try {
tracker = new MediaTracker( this );
tracker.addImage( image, 0 );
tracker.waitForID(0);
}
catch ( InterruptedException i_excp ) {
System.err.println("Oops, failed to load image into Media
Tracker.");
}
return image ;
}
catch ( IOException io_excp )
{
System.err.println("Oops, got I/O error.");
}
If gifName contains an embedded blank, I set the URL okay (it is NOT null),
but url.getContent() blows up; I get:
java.io.FileNotFoundException: JAR entry Images/Checkered%20Flag.jpg not
found in E:\eclipse\3.0.1\eclipse\workspace\Project1\jarProject1Media.jar
I'm certain that the jar contains a file called Images/Checkered Flag.jpg.
How do I improve this code so that it can read an image file when the file
name contains embedded spaces? (I assume that I will also have problems if
the jar file name contains embedded blanks so if you know now to make my
code handle THAT situation properly too, I'd appreciate hearing the
solution!)
I am using J2SE 1.5 on Windows XP.
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare
code to get and read those files working satisfactorily except for one
thing: if the file name (of the image file, as opposed to the file name of
the jar) contains an imbedded blank, my reading logic fails.
For example, if the jar is called My.jar and the icon file I want is called
Foo.gif, everything works fine. But if the icon file is called Foo Bar.gif,
my logic fails. I would like my code to work even if embedded blanks occur
in the file name but I'm not sure how to accomplish it. I've googled but
haven't found anything that solves the problem.
Here is the relevant fragment of my code:
try {
URL url = this.getClass().getResource( gifName );
if ( url == null ) {
System.err.println("File " + gifName + " not found.");
}
Image image =
Toolkit.getDefaultToolkit().createImage((ImageProducer) url.getContent() );
// wait till it is loaded
MediaTracker tracker;
try {
tracker = new MediaTracker( this );
tracker.addImage( image, 0 );
tracker.waitForID(0);
}
catch ( InterruptedException i_excp ) {
System.err.println("Oops, failed to load image into Media
Tracker.");
}
return image ;
}
catch ( IOException io_excp )
{
System.err.println("Oops, got I/O error.");
}
If gifName contains an embedded blank, I set the URL okay (it is NOT null),
but url.getContent() blows up; I get:
java.io.FileNotFoundException: JAR entry Images/Checkered%20Flag.jpg not
found in E:\eclipse\3.0.1\eclipse\workspace\Project1\jarProject1Media.jar
I'm certain that the jar contains a file called Images/Checkered Flag.jpg.
How do I improve this code so that it can read an image file when the file
name contains embedded spaces? (I assume that I will also have problems if
the jar file name contains embedded blanks so if you know now to make my
code handle THAT situation properly too, I'd appreciate hearing the
solution!)
I am using J2SE 1.5 on Windows XP.
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare