希望能给出代码!!多谢!
解决方案 »
- 问大家关于java的IO流这边的几个问题,希望能得到你们的答案,谢谢了!
- 如何使Jtable自动处于最底端
- 关于JAVA中如何判断一个文件是否正在被上传
- Ant中如何引用第三方的jar包,怎么在build.xml中配置
- 求java基础习题
- JAVA打印的问题,打印机是:Epson LQ-300K
- 求救!!!!!!!!!!
- 如何使Frame变成我所需要的那么大?(Jbuilder中)
- 如何写一个把ResultSet纪录做成哈希表的方法??/拜托了
- 配置jdk+tomcat的遇到的问题 望不吝赐教 ^_^
- 怎么样得到每年每个星期的开始结束日期---着急--路过的帮忙
- 大家来看看这2个程序要怎么理解
URL url=new URL(tagetURL);
InputStream is=url.openStream();或socket方式
以类似的方式构造出HTTP header----------------------------------------------------------------
String header = "GET " + httpreq + " HTTP/1.1\r\n";
header += "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, application/x-icq, */*\r\n";
header += "Accept-Language: zh-cn\r\n";
header += "Accept-Encoding: gzip, deflate\r\n";
header += "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Maxthon; .NET CLR 1.0.3705)\r\n";
header += "Host: " + host + "\r\n";
header += "Connection: Keep-Alive\r\n";
--------------------------------------------------------------------------------然后: InetAddress addr = InetAddress.getByName(host);
Socket socket = new Socket(addr);
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
os.write(sb.toString().getBytes());
os.flush();
import java.io.*;public class URLReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.yahoo.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahoo.openStream())); String inputLine; while ((inputLine = in.readLine()) != null)
System.out.println(inputLine); in.close();
}
}
import java.io.*;public class URLReader {
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("usage: java URLReader <a URL>");
System.exit(0);
} URL yahoo = new URL(args[0]);
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahoo.openStream())); String inputLine; while ((inputLine = in.readLine()) != null)
System.out.println(inputLine); in.close();
}
}