Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35190

A little help with some logic

From Knute Johnson <nospam@rabbitbrush.frazmtn.com>
Newsgroups comp.lang.java.programmer
Subject A little help with some logic
Date 2016-08-03 21:39 -0700
Organization A noiseless patient Spider
Message-ID <nnugtj$78m$1@dont-email.me> (permalink)

Show all headers | 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


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