open URL connection very slow
- I use this code to get website content, and my problem is:
+ when i use it first, it starting very slow, but a second, third....., it starting very fast.
+ i want know how?, why? and the way to solve it.
Thanks.
Here is my code:
import java.io.*;
import java.net.*;
publicclass IOTool{
staticboolean use_proxy =false;
static Proxy proxy;
publicstatic String get(String str_url){
try{
URL url =new URL(str_url);
URLConnection urlCon;
try{
urlCon = url.openConnection();
BufferedReader r =new BufferedReader(new InputStreamReader(urlCon.getInputStream(),"UTF-8"));
StringBuffer raw =new StringBuffer();
char[] buffer =newchar[8192];
int len;
while((len = r.read(buffer)) != -1){
raw.append(buffer, 0, len);
}
r.close();
return raw.toString();
}catch(IOException e){
e.printStackTrace();
}
}catch(MalformedURLException e){
e.printStackTrace();
}
returnnull;
}
}
Message was edited by:
NhTin

