搞笑来。这里是探讨和解疑技术问题的地方,不是免费troubleShooting的地方,不是技术支持。凭什么要人家给你改代码。把你的本月工资分给我一半,我就替你解决这个问题。
解决方案 »
- GridLayout怎样自定义每一列高度?
- 假如我在操作数据库的dao未写.close()会怎样
- jdom&xml
- java
- 关于Class [Ljava.lang.String 和 Class java.lang.String的区别
- 【调查】做J2EE的项目开发时,在使用windows操作系统的文件系统的时候,特别不爽,有同感的进来领分
- 如果对通过comparator接口对 treemap中的值进行排序?
- 如何解决主线程根据当前时间对不同的子线程进行启动和停止的问题,要求不能太耗资源,而且要稳定。
- 求教TextField与JTextField的区别?
- 哪儿的JDK可用蚂蚁下载,提供地址一定给分!!!
- 关于多个线程结束的问题?
- 关于异常处理的问题,怎样把异常转换为用户能看懂的信息
import java.net.*;
public class URLClient2 {
protected URLConnection connection;
public static void main(String[] args) {
URLClient2 client = new URLClient2();
String yahoo = client.getDocumentAt("http://www.163.com");
System.out.println(yahoo);
}public String getDocumentAt(String urlString) {
StringBuffer document = new StringBuffer();
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = null; while ((line = reader.readLine()) != null){
document.append(line + "\n");//读到文件
//********************3
File f=new File("163.txt");
FileWriter fw=new FileWriter(f,true);//参数 true
fw.write(line);
fw.close();
//********************3
}reader.close();
} catch (MalformedURLException e) {
System.out.println("Unable to connect to URL: " + urlString);
} catch (IOException e) {
System.out.println("IOException when connecting to URL: " + urlString);
}
return document.toString(); }
}
不过这段代码我早已经写过。
但是我觉得这段代码的效率不够高。
http://community.csdn.net/Expert/topic/3156/3156164.xml?temp=.3702661
我只是想看看java.nio.*和java.io.*之间比较
看看java.nio.*的非堵塞在我的程序中能否起到提高效率作用。
也就是向SocketChannel发送数据GET /test/test.htm HTTP1.0\n\n,
从服务器返回的数据也要处理HTTP协议.