Create a URL pointing to C:\

Hey all!

How would I go about creating a URL that references to html files on my hard-drive? I’ve tried to create a new URL object and sending the constructor strings like “file://C:/test.html”, “file://C:\test.html”, and “c:\test.html” but none of them seem to work.

Heres the


package CarringtonPlace.Help;
import CarringtonPlace.IView.IBEIView;
import CarringtonPlace.Model.HelpBook;
import CarringtonPlace.Model.Constants;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.UIManager;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

import java.io.File;

import java.net.URL;
import java.io.IOException;
import java.awt.Dimension;
import java.awt.GridLayout;


/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class HelpHTMLPane extends JEditorPane implements IBEIView
{  private HelpBook model;

   private URL helpURL;

   public HelpHTMLPane(HelpBook theModel) 
   {  super();
      this.model = theModel;
      
      this.initializeHelp();
      
      
      this.model.addView(this);
   }
   
   private void initializeHelp() 
   {  //String s = "http://www.icebreakersentertainment.com";
      //String s = "file://" + Constants.HELP_PATH + "test.html";
      //String s = "test.html";
      String s = "file://C:/test.html";
      //System.out.println(s);
      
      try
      {  this.helpURL = new URL(s);
      } catch (Exception e)
      {  System.err.println("Could not parse URL address.");
      }
      
      //this.helpURL = HelpHTMLPane.class.getResource("Main.html");
      if (helpURL == null) 
      {  System.err.println("Couldn't open help file: " + s);
      } else 
      {  System.out.println("Help URL is " + this.helpURL);
      }
      
      this.displayURL(helpURL);
   }
   
   private void displayURL(URL url) 
   {  try 
      {  if (url != null) 
         {  this.setPage(url);
         } else 
         {  //null url
            this.setText("File Not Found");
            System.out.println("Attempted to display a null URL.");
         }
      } catch (IOException e) 
      {  System.err.println("Attempted to read a bad URL: " + url);
      }
   }

   
   public void updateView()
   {
   }
   
   public void updateColors()
   {
   }

}

I’d appreciate any input on this!

Thx,

Jarrett
aka. Chisser98

OHH MANN…I just figured it out. Its one of those things that when you’ve got it you want to rip your hair out and scream “Gimme a break!”.

All I need to do was change “file://c:/test.html” to “file:///c:/test.html” ! I needed an extra “/” after the “file://”…ohhhh maann…lol!

I hope this helps someone else if they have this problem!

Regards,
Jarrett
aka. Chisser98

In case you are still wondering why this is so:

An URL consists of :///.
An URL of the form file:/// has an empty hostname part, meaning localhost, that’s all.

Ahh ok. That makes sense. Thank you for the clarification.

Regards,
Jarrett
aka. Chisser98