Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35190
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | A little help with some logic |
| Date | Wed, 3 Aug 2016 21:39:15 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 33 |
| Message-ID | <nnugtj$78m$1@dont-email.me> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 4 Aug 2016 04:39:15 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="fc10d1b501433caa198830294d826923"; logging-data="7446"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+U6bVrtYqKycfmFI+CJvHc" |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
| X-Mozilla-News-Host | news://news.eternal-september.org:119 |
| Cancel-Lock | sha1:uo9SItZQWNltaNGT5anUc+DQP3c= |
| Xref | csiph.com comp.lang.java.programmer:35190 |
Show key headers only | View raw
I don't know maybe it is too late but I can't seem to come up with
anything better than this. What I need to do is take a String that
contains the name of a file in my program's JAR file, a URL for a
network site or the name of a file on the accessible file system and
turn it into a URI. I want to check in that order, in the JAR file, a
file on the filesystem or a network reachable URL. Even this has some
holes and it is really ugly. Thanks...
URI uri = null;
URL url = getClass().getResource(fname);
if (url == null) {
try {
url = new URL(fname);
} catch (MalformedURLException murle) {
uri = new File(fname).toURI();
}
}
if (uri == null) {
try {
uri = url.toURI();
} catch (URISyntaxException urise) {
urise.printStackTrace();
}
}
if (uri != null)
// do something with the URI
--
Knute Johnson
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
A little help with some logic Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-08-03 21:39 -0700
Re: A little help with some logic Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-04 09:28 -0400
Re: A little help with some logic Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-08-04 16:44 -0700
Re: A little help with some logic Robert Klemme <shortcutter@googlemail.com> - 2016-08-06 11:13 +0200
csiph-web