Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #21479
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | markspace <markspace@nospam.nospam> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: resources from JAR files |
| Date | Thu, 17 Jan 2013 08:54:14 -0800 |
| Organization | A noiseless patient Spider |
| Lines | 30 |
| Message-ID | <kd9abp$t6b$1@dont-email.me> (permalink) |
| References | <f7a28e33-5e29-45fd-8c15-762e8ee4cdc2@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 17 Jan 2013 16:54:17 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="fba3415ba68d85d643935af2f52f0b4b"; logging-data="29899"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19LciYZN3jeffheLH82y7s/GpagzSTlav8=" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 |
| In-Reply-To | <f7a28e33-5e29-45fd-8c15-762e8ee4cdc2@googlegroups.com> |
| Cancel-Lock | sha1:xmbsfiSUS0uMWEKI0So88GozKlQ= |
| Xref | csiph.com comp.lang.java.programmer:21479 |
Show key headers only | View raw
On 1/17/2013 8:30 AM, bob smith wrote:
> I have some code that reads an image from its JAR file like so:
>
> img = ImageIO.read(frame.getClass().getResource("whatever.jpg"));
>
> I basically just picked the "frame" object at random to call the getClass() method on it.
>
> Is there a way to do this without picking an arbitrary object? It seems so wrong.
>
Yes, normally I use the object the line of code is contained it.
class MyBusinessObject {
void someMethod() {
Image img ImageIO.read( getClass().getResource( "whatever.jpg" ));
// etc...
}
}
You can also use a constant. MyBusinessObject.class.getResource(...)
instead of getClass().
You can also use
Thread.currentThread().getContextClassLoader().getResource(...), but
that's usually only useful in situations where thread contexts are used,
i.e. web apps.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
resources from JAR files bob smith <bob@coolfone.comze.com> - 2013-01-17 08:30 -0800
Re: resources from JAR files markspace <markspace@nospam.nospam> - 2013-01-17 08:54 -0800
Re: resources from JAR files Roedy Green <see_website@mindprod.com.invalid> - 2013-01-17 15:07 -0800
Re: resources from JAR files Lew <lewbloch@gmail.com> - 2013-01-17 15:16 -0800
Re: resources from JAR files Roedy Green <see_website@mindprod.com.invalid> - 2013-01-17 16:36 -0800
Re: resources from JAR files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-17 19:44 -0500
Re: resources from JAR files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-17 18:13 -0500
Re: resources from JAR files BGB <cr88192@hotmail.com> - 2013-01-25 15:08 -0600
Re: resources from JAR files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-25 20:57 -0500
Re: resources from JAR files Lew <lewbloch@gmail.com> - 2013-01-25 22:32 -0800
csiph-web