I need to "read" a lot of links with slightly different URLs for further parsing. Using this code:
String charset = "UTF-8";
System.setProperty("java.net.useSystemProxies", "false");
//System.out.println(http);
//System.out.println(html);
URL pageToRead = new URL(http);
URLConnection yc = pageToRead.openConnection();
yc.setRequestProperty("Accept-Charset", charset);
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
FileWriter fstream = new FileWriter(html);
BufferedWriter out = new BufferedWriter(fstream);
while ((inputLine = in.readLine()) != null) {
out.write(inputLine);
}
in.close();
out.close();
Note about variables: http
is String with the full URL. html
is String with full file name.
Two questions:
- How to change this code to read URLs faster?
- Maybe I am wrong and the problem is in the http server. Maybe it just can't give me pages faster. How to check it?