Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages
Started by Raydog
Fri, 09 Apr 2004 19:22
[JbX read image] trouble with reading image file
Author: Raydog
Date: Fri, 09 Apr 2004 19:22
Date: Fri, 09 Apr 2004 19:22
27 lines
1628 bytes
1628 bytes
hi , i am trying to read in a png image with the following code:
public class BK extends JPanel {
BufferedImage image;
int w,h;
public BK() {
try {
image = ImageIO.read(new File("bk.png"));
w = image.getWidth();
h = image.getHeight();
} catch (IOException ioe) {
System.out.println(ioe);
System.exit(0);
}
}
==========================
this code works fine when i use JCreator 3,
but the exact code when i try to build&run under JBuilderX it always gives
exception
"cannot read file"
I have been stuck with this for a while, i hope someone could give me some
hint.
THanks so muchm
raydog
Re: [JbX read image] trouble with reading image file
Author: Lori M Olson (TeamB)
Date: Fri, 09 Apr 2004 21:58
Date: Fri, 09 Apr 2004 21:58
60 lines
2778 bytes
2778 bytes
Raydog wrote:
> hi , i am trying to read in a png image with the following code:
>
> public class BK extends JPanel {
> BufferedImage image;
> int w,h;
>
> public BK() {
> try {
> image = ImageIO.read(new File("bk.png"));
> w = image.getWidth();
> h = image.getHeight();
> } catch (IOException ioe) {
> System.out.println(ioe);
> System.exit(0);
> }
> }
> ==========================
> this code works fine when i use JCreator 3,
> but the exact code when i try to build&run under JBuilderX it always gives
> exception
> "cannot read file"
>
> I have been stuck with this for a while, i hope someone could give me some
> hint.
>
> THanks so muchm
> raydog
>
>
So where is this bk.png file located? If you are running this from
inside JBuilder, then you should know that user.dir (the "current"
directory) points to the <jbuilder>\bin directory, so the new
File("bk.png") will only work if you place bk.png in that directory.
If you are placing the bk.png file in the classpath, in the same
directory as the BK class, then you need to reference it like this :
getClass().getResourceAsStream("bk.png")
--
Regards,
Lori Olson (TeamB)
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads