4 Replies Latest reply: Jul 16, 2008 2:44 PM by 843785 RSS

    java.net.MalformedURLException: unknown protocol: c

    800328
      here is my source code...
      package testing;
      
      import org.w3c.tidy.*;
      import java.io.*;
      import org.w3c.dom.*;
      import java.net.*;
      
      class tidytest{
           public static void main(String args[]){
           String tempString = " ";
                try{
                
           
           File f = new File("file://C:/file.txt");
           InputStream in = new URL (  "C://abc.html"  ).openStream();      
                
           OutputStream out = new FileOutputStream(f);
           
           Tidy tidy = new Tidy();
           tidy.parse(in,out);
           
           
           
           
           }
           catch(Exception e){
                e.printStackTrace();
           }
      }
      }
      and the error i am getting at run time is
      C:\Documents and Settings\sumit-i\Desktop>java testing.tidytest
      java.net.MalformedURLException: unknown protocol: c
              at java.net.URL.<init>(Unknown Source)
              at java.net.URL.<init>(Unknown Source)
              at java.net.URL.<init>(Unknown Source)
              at testing.tidytest.main(tidytest.java:24)
      any ideas plzz..
        • 1. Re: java.net.MalformedURLException: unknown protocol: c
          DrClap
          You didn't connect the "C:" in the error message with the "C:" in the line of code which the error message referred to?

          That string isn't a valid URL. It's a file path. Anyway, why would you use new URL().getInputStream() on a file path when you could just use a FileInputStream?
          • 2. Re: java.net.MalformedURLException: unknown protocol: c
            800328
            ok..i changed the code to
            package testing;
            
            import org.w3c.tidy.*;
            import java.io.*;
            import org.w3c.dom.*;
            import java.net.*;
            
            class tidytest{
                 public static void main(String args[]){
                 String tempString = " ";
                      try{
                      
                 
                 File f = new File("file://C:/file.txt");
                 InputStream in = new FileInputStream(  "C://abc.html"  );      
                      
                 OutputStream out = new FileOutputStream(f);
                 
                 Tidy tidy = new Tidy();
                 tidy.parse(in,out);
                 
                 
                 
                 
                 }
                 catch(Exception e){
                      e.printStackTrace();
                 }
            }
            }
            and the error i am getting is
            C:\Documents and Settings\sumit-i\Desktop>java testing.tidytest
            java.io.FileNotFoundException: file:\C:\file.txt (The filename, directory name, or volume label synt
            ax is incorrect)
                    at java.io.FileOutputStream.open(Native Method)
                    at java.io.FileOutputStream.<init>(Unknown Source)
                    at java.io.FileOutputStream.<init>(Unknown Source)
                    at testing.tidytest.main(tidytest.java:26)
            what should i do now
            • 3. Re: java.net.MalformedURLException: unknown protocol: c
              843785
              ping.sumit wrote:
              what should i do now
              Learn to interpret stack traces
              • 4. Re: java.net.MalformedURLException: unknown protocol: c
                843785
                First you used a file path, where an URL was expected. Now you're using an URL where a File-path is expected.

                Also, as georgemc said: learn to interpret stack traces and error messages.