我用nio编了一个下载网页的程序:
Charset charset=Charset.forName("gb2312"); SocketChannel sc=SocketChannel.open(new java.net.InetSocketAddress("www.baidu.com", 80));
System.out.println("has open port 80!");
sc.configureBlocking(false);
想要下载百度的index.html,求request怎么写?
读文件的时候
是这样读的吗(SocketChannel是sc,ByteBuffer是bb)?
while(sc.read(bb)!=-1){
System.out.println(charset.decode(bb));
}
Charset charset=Charset.forName("gb2312"); SocketChannel sc=SocketChannel.open(new java.net.InetSocketAddress("www.baidu.com", 80));
System.out.println("has open port 80!");
sc.configureBlocking(false);
想要下载百度的index.html,求request怎么写?
读文件的时候
是这样读的吗(SocketChannel是sc,ByteBuffer是bb)?
while(sc.read(bb)!=-1){
System.out.println(charset.decode(bb));
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货