By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

MalformedURLException

P: n/a
Could someone kindly suggest why the following Java application, which
reads a list of URLs to download from a file, gives a
java.net.MalformedURLException if any of the URLs is of the type
https://.....

//////////// Source Listing Begin ///////////////
import java.io.*;
import java.net.*;

class WebsiteLoader
{
public static char replaceChar = '~';

public static void main(String argv[]) throws IOException
{
BufferedReader br;
String origName;

if(argv.length != 0)
{
br = new BufferedReader(new FileReader(argv[0]));

for(;;)
{
origName = br.readLine();
if(origName == null)
break;

origName = origName.trim();

if(origName.length() == 0)
continue; // Skip blank lines

if(origName.charAt(0) == '#')
continue; // Skip lines beginning with the '#' character

URL url = new URL(origName);
if(url == null)
continue;

//FileInputStream fileIpStm = new
FileInputStream(url.openStream());
DataInputStream dataIpStm = new
DataInputStream(url.openStream());
//BufferedReader bufRdr = new BufferedReader(dataIpStm);

String modName = origName;

modName = modName.replace('\\', replaceChar);
modName = modName.replace('/', replaceChar);
modName = modName.replace(':', replaceChar);
modName = modName.replace('*', replaceChar);
modName = modName.replace('?', replaceChar);
modName = modName.replace('"', replaceChar);
modName = modName.replace('<', replaceChar);
modName = modName.replace('>', replaceChar);
modName = modName.replace('|', replaceChar);

FileWriter fWriter = new FileWriter(modName);
System.out.println("Writing contents of " + origName + " to "
+
"the following file: " + modName);
for(;;)
{
String thisLine = dataIpStm.readLine();
if(thisLine == null)
break;

fWriter.write(thisLine);
}

}
}
}
}
//////////// Source Listing End ///////////////
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Generic Usenet Account" <us****@sta.samsung.com> wrote in message
news:90*************************@posting.google.co m...
Could someone kindly suggest why the following Java application, which
reads a list of URLs to download from a file, gives a
java.net.MalformedURLException if any of the URLs is of the type
https://.....

According to the docs, that exception is thrown for an unknown protocol in
the String. What is the complete exception and message and possibly
stacktrace? Also, in the future post to comp.lang.java.help for basic
questions and comp.lang.java.programmer for advanced issues. This group is
not carried by all news servers.
Jul 17 '05 #2

P: n/a
Search for "URLConnection https" on Google and you'll get a lot of useful
links.

"Generic Usenet Account" wrote:
Could someone kindly suggest why the following Java application, which
reads a list of URLs to download from a file, gives a
java.net.MalformedURLException if any of the URLs is of the type
https://.....

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.