Article View: borland.public.jbuilder.java.swing
Article #1124Re: [JbX read image] trouble with reading image file
From: 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
Technical Details
Message-ID:
<40771c9b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4076f7e8@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,424df1da00210b82 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-04-09 15:09:41 PST Date: Fri, 09 Apr 2004 15:58:21 -0600 From: "Lori M Olson (TeamB)" <javadragon@techie.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax; CDonDemand-Dom) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing Subject: Re: [JbX read image] trouble with reading image file References: <4076f7e8@newsgroups.borland.com> In-Reply-To: <4076f7e8@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 142.179.181.200 Message-ID: <40771c9b$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1081547931 142.179.181.200 (9 Apr 2004 14:58:51 -0800) Lines: 61 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail