import java.io.*; import java.net.*; class Test { public static void main(String s[]) { int b; try { String str=""; String fileUrl = "";//地址 URL url = new URL(fileUrl); InputStream is = url.openStream(); BufferedInputStream bis = new BufferedInputStream(is);
输入ULR地址读取网页全文。
*/import java.net.*;
import java.io.*;
public class ReadURLfile{
static public String getURL(String u)
{
URL url;//
InputStream is;//
InputStreamReader isr;
BufferedReader r;
String str;
String totalStr="";
StringBuffer sb;
//-------------
try{
url= new URL(u);
is =url.openStream();
isr=new InputStreamReader(is);
r=new BufferedReader(isr);
sb=new StringBuffer();
while((str=r.readLine())!=null)
{
sb.append(str);
//System.out.println(str);
}
totalStr=sb.toString();
return totalStr;
}
catch(MalformedURLException e){
System.out.println("必须是有效的URL地址");
}
catch(IOException e){
System.out.println("不能连接!");
return null;
} //-------------
return null;
}
}
import java.net.*;
class Test
{
public static void main(String s[])
{
int b;
try
{
String str="";
String fileUrl = "";//地址
URL url = new URL(fileUrl);
InputStream is = url.openStream();
BufferedInputStream bis = new BufferedInputStream(is);
while((b=is.read())!=-1)
{
str = str+(char)b;
}
is.close();
bis.close();
str = new String(str.getBytes("ISO-8859-1"),"GB2312");
System.out.println (str);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}