title: Overcoming java.net.MalformedURLException: no protocol Exception
body: <p>I have a properties file that contains a property specifying the URL of a NOAA web site containing a temperature data set. The property contains a <code>[DATE_REPLACE]</code> token because the URL changes daily when NOAA generates a new forecast.</p>
  
  <p>In my properties file, I am specifying:</p>
  
  <pre><code>WEATHER_DATA_URL="http://weather.noaa.gov/pub/SL.us008001/DF.anf/DC.mos/DS.mex/RD.[DATE_REPLACE]/cy.00.txt"
  </code></pre>
  
  <p>I have declared a method withing a PropertyHelper class (a wrapper for java.util.Properties) to generate the URL String for the current day using <code>WEATHER_DATA_URL</code> as the name, "<em>yyyyMMdd</em>" as the date format, a today's Date.</p>
  
  <pre><code>public String getPropertyWithDateReplaceToken(String name, String dateFormat, Date dateToFormat)
  {
      String value = this.properties.getProperty(name);
  
      if (StringHelper.isNullOrWhitespace(value) || !value.contains("[DATE_REPLACE]"))
      {
          throw new UnsupportedOperationException("The property value should specify the [DATE_REPLACE] token");
      }
  
      StringBuilder sb = new StringBuilder(value);
      int index = sb.indexOf("[DATE_REPLACE]");
      while (index != -1)
      {
          String replacement = StringHelper.getTodayAsDateString(dateFormat, dateToFormat);
          sb.replace(index, index + "[DATE_REPLACE]".length(), replacement);
          index += replacement.length();
          index = sb.indexOf(value, index);
      }
  
      return sb.toString();
  }
  </code></pre>
  
  <p>I then call another helper class with the following method to read the text from the web page:</p>
  
  <pre><code>public static List&lt;String&gt; readLinesFromWebPage(String urlText) throws Exception
  {
      List&lt;String&gt; lines = new ArrayList&lt;String&gt;();
      if (StringHelper.isNullOrWhitespace(urlText))
      {
          throw new NullPointerException("URL text cannot be null or empty");
      }
  
      BufferedReader dataReader = null;
      try
      {
          System.out.println("URL = " + urlText);
          String trimmedUrlText = urlText.replaceAll("\\s", "");
  
          URL url = new URL(trimmedUrlText);
          dataReader = new BufferedReader(new InputStreamReader(url.openStream()));
  
          String inputLine;
          while((inputLine = dataReader.readLine()) != null)
          {
              lines.add(inputLine);
          }
  
          return lines; 
      }
      catch(Exception e)
      {
          logger.logThrow(Level.SEVERE, e, "Exception (" + e.getMessage() + ") attempting to " +
                  "read data from URL (" + urlText + ")");
          throw e;
      }
  }
  </code></pre>
  
  <p>As you can see I have tried to trim spaces from the generated URL String in the hopes that that was causing the issue.  The URL string is generated properly but I am getting the following exception:</p>
  
  <pre><code>java.net.MalformedURLException: no protocol: "http://weather.noaa.gov/pub/SL.us008001/DF.anf/DC.mos/DS.mex/RD.20121219/cy.00.txt"
  </code></pre>
  
  <p>If I set the string manually, everything works ... what am I missing?</p>