importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileWriter;importjava.io.IOException;importjava.io.InputStreamReader;importjava.net.HttpURLConnection;importjava.net.URL;public classjavaurl {public staticString getURLContent(String urlStr) {
URL url= null; /**网络的url地址*/HttpURLConnection httpConn= null; /**http连接*/BufferedReader in= null; /**//** 输入流*/StringBuffer sb= newStringBuffer();long start=System.currentTimeMillis();try{
url= newURL(urlStr);
in= new BufferedReader( new InputStreamReader(url.openStream(),"UTF-8") );
String str= null;while((str = in.readLine()) != null) {
sb.append( str );
}
}catch(Exception ex) {
ex.printStackTrace();
}finally{try{if(in!=null) {
in.close();
}
}catch(IOException ex) {
ex.printStackTrace();
}
}
String result=sb.toString();//System.out.println(result);
long ks=System.currentTimeMillis() -start;
File f2=new File("./A.txt");
FileWriter writer= null;try{
writer= new FileWriter(f2,true);
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}
BufferedWriter bw= newBufferedWriter(writer);try{
bw.write(url+" "+ks+"ms");
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}try{
bw.newLine();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}try{
bw.flush();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}returnresult;
}
}