Menu

how to open local file

Joe
2006-11-07
2013-04-30
  • Joe

    Joe - 2006-11-07

    hello,
    I would like to use browser launcher to launch a manual.html file from within my desktop application.
    With external html-files, everything works fine, but I don't know how to do it with local files and a relative path. With a url file://../manual.html I cannot get it work.
    I am really grateful for all kinds of help or advice.

    Greetings
    joe

    PS: Currently I am using the fatjar plugin for eclipse to pack my program into a jar-File.

     
    • sairanjit

      sairanjit - 2006-11-08

      for handling local files
      try {
      BrowserLauncher launcher = new BrowserLauncher(null);
      File helpFile=new File("Help/introduction.html");//this is an example location
      String urlString;
      try {
      //here i converted the relative path of the file to url and passing that url string.
      urlString = helpFile.toURL().toString();
      launcher.openURLinBrowser(urlString);
      } catch (MalformedURLException e) {
      e.printStackTrace();
      }
      }
      catch (BrowserLaunchingInitializingException ex) {
      ex.printStackTrace();
      }
      catch (BrowserLaunchingExecutionException ex) {
      ex.printStackTrace();
      }
      catch (UnsupportedOperatingSystemException ex) {
      ex.printStackTrace();
      }
      you can well handle local files like this.

      Regards
      Sai

       
    • Joe

      Joe - 2006-11-08

      Thanks a lot Sai,

      worked out perfectly! I did not make this "file to url to string transformation", I always tried to make a ../../doe reference, which was not very succesfull.

      Greetings, Joe

       

Log in to post a comment.