Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Failed: InputStream in = getClass().getResourceAsStream("1.txt");

Reply
Thread Tools

Failed: InputStream in = getClass().getResourceAsStream("1.txt");

 
 
Roedy Green
Guest
Posts: n/a
 
      09-05-2005
On Mon, 5 Sep 2005 17:45:12 +0800, "Boki" <(E-Mail Removed)>
wrote or quoted :

>imageName


image name will be something like "dalmatian.jpg"
It will be a resource living in the jar file under a name like:
com/mindprod/mypackage/dalmatian.jpg

It will not be called 1.txt. It is a picture, not text.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-05-2005
On Mon, 5 Sep 2005 17:45:12 +0800, "Boki" <(E-Mail Removed)>
wrote or quoted :

>imageSource = getClass().getResourceAsStream(imageName);


Let's do a simple getResource to help you understand what is
happening:

URL url = this.getClass().getResource( "blueball.gif" );

System.out.println( url );

Your first problem is to find the resource. If 1.txt truly is an
image, pleace rename it to the proper .png .jpg .gif suffix and put it
in the jar in the same package as your code.

See http://mindprod.com/jgloss/image.html
for what sort of response you should expect.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-05-2005
On Mon, 05 Sep 2005 12:33:38 GMT, "jan V" <(E-Mail Removed)> wrote or quoted
:

>Use some kind of logical sorting order for your imports, and use this order
>consistently. Interleaving java.* and javax.* imports is a no-no in my book.
>I also import home-grown packages first (your de.*) to highlight the fact
>that the current source file relies on non-standard packages.


This is most easily fixed by an IDE such as Eclipse that will sort and
expand *s for you.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-05-2005
On Mon, 05 Sep 2005 12:33:38 GMT, "jan V" <(E-Mail Removed)> wrote or quoted
:

>> catch (Throwable e) {

>
>Never catch everything like this, use explicit sub-exception types.


Never is perhaps too strong a word, but as generic advice, you want to
avoid being overly greedy in the exception nets you cast. Throwable
includes even extremely fatal situations you can't recover from. Best
just let them flow.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-05-2005
On Mon, 5 Sep 2005 17:30:57 +0800, "Boki" <(E-Mail Removed)>
wrote or quoted :

>Hi,
> I am really no good on java....


Nobody is to start. Just keep plugging. People would not be spending
so much time on you if they did not think you had promise.


--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-05-2005
On 5 Sep 2005 08:48:44 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote or quoted
:

>Thank you very much, but no luck on me....
>
>sigh..... just to read a file...


The funny thing is ONCE YOU GET IT GOING, you will wonder what all the
fuss was about and why you had so much trouble. It is like tripping
over a paperclip.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-05-2005
On 5 Sep 2005 09:27:42 -0700, (E-Mail Removed) wrote or quoted
:

>I just change 1.txt to a.jpg ( and put a.jpg to the same folder )
>
>and I can read it !!!!!!!


Congratulations:

To cap your success, please read http://mindprod.com/jgloss/image.html
that will explain to you WHY it worked, and other similar useful
information. Read it now while the pain is still fresh.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
jan V
Guest
Posts: n/a
 
      09-05-2005
> >Use some kind of logical sorting order for your imports, and use this
order
> >consistently. Interleaving java.* and javax.* imports is a no-no in my

book.
> >I also import home-grown packages first (your de.*) to highlight the fact
> >that the current source file relies on non-standard packages.

>
> This is most easily fixed by an IDE such as Eclipse that will sort and
> expand *s for you.


Sure thing. One side-effect of such IDE support that I've noticed in
colleagues (though not in me..) is that people start not to give a f*ck
about what's in their imports anymore. The IDE deals with that to such an
extreme extent that the programmer can completely forget that part of the
language.

.... and that's the problem.

When you start ignoring your imports, you start ignoring a decent source of
dependency information. A class which needs a list of imports the size of
your Christmas shopping list is a diseased class (most likely).

Call me old-fashioned, but I like to keep an eye on my imports, even if it
means sorting and formatting them myself.


 
Reply With Quote
 
jan V
Guest
Posts: n/a
 
      09-05-2005
> What the pig,
>
> I just change 1.txt to a.jpg ( and put a.jpg to the same folder )
>
> and I can read it !!!!!!!


Life's a bitch, a lot of the time. I'm happy you're a step closer to reading
that mysterious 1.txt though


 
Reply With Quote
 
Patricia Shanahan
Guest
Posts: n/a
 
      09-05-2005
jan V wrote:
>>>Use some kind of logical sorting order for your imports, and use this

>
> order
>
>>>consistently. Interleaving java.* and javax.* imports is a no-no in my

>
> book.
>
>>>I also import home-grown packages first (your de.*) to highlight the fact
>>>that the current source file relies on non-standard packages.

>>
>>This is most easily fixed by an IDE such as Eclipse that will sort and
>>expand *s for you.

>
>
> Sure thing. One side-effect of such IDE support that I've noticed in
> colleagues (though not in me..) is that people start not to give a f*ck
> about what's in their imports anymore. The IDE deals with that to such an
> extreme extent that the programmer can completely forget that part of the
> language.
>
> ... and that's the problem.
>
> When you start ignoring your imports, you start ignoring a decent source of
> dependency information. A class which needs a list of imports the size of
> your Christmas shopping list is a diseased class (most likely).
>
> Call me old-fashioned, but I like to keep an eye on my imports, even if it
> means sorting and formatting them myself.
>
>


I had the opposite experience. When I did the imports by hand, I tended
to use on-demand imports, such as "java.util.*". With Eclipse doing the
bookkeeping, I stick to single class imports. The length of the import
list is a much better indication of the number of imported classes.

Patricia
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
confused: Socket InputStream != ServerSocker InputStream R Java 5 03-13-2005 07:26 AM
ASP.NET InputStream is not a stream Steve Drake ASP .Net 7 10-18-2004 06:57 AM
changing Request.InputStream karahan celikel ASP .Net 4 03-04-2004 05:24 PM
Email attachment from InputStream? steven shingler ASP .Net 1 01-20-2004 06:58 AM
Re: Accessing Request.InputStream / Request.BinaryRead *as the request is occuring*: How??? Brian Birtle ASP .Net 2 10-16-2003 02:11 PM



Advertisments