问题描述
importjava.net.*;importjava.io.*;importjava.util.Scanner;publicclassURLDemo{publicstaticvoidmain(String[]args)throwsException{URLurl=newURL("htpp","www.mldnjava.cn",80,"/project.htm");InputStreaminput=url.openStream();Scannerscan=newScanner(input);scan.useDelimiter("n");while(scan.hasNext()){System.out.println(scan.next());}}}编译后出现--------------------Configuration:<Default>--------------------Exceptioninthread"main"java.net.MalformedURLException:unknownprotocol:htppatjava.net.URL.<init>(URL.java:395)atjava.net.URL.<init>(URL.java:283)atURLDemo.main(URLDemo.java:17)Processcompleted.
解决方案
解决方案二:
URLurl=newURL("htpp","www.mldnjava.cn",80,"/project.htm");改为URLurl=newURL("http","www.mldnjava.cn",80,"/project.htm");
时间: 2024-09-20 10:39:47