1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public static String download(String urlString) throws IOException {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2");
conn.connect();
InputStreamReader inputReader = new InputStreamReader(conn.getInputStream());
try{
StringBuffer content = new StringBuffer();
char[] c = new char[2048];
int r;
while ( (r=inputReader.read(c)) > 0 ) {
content.append(c,0,r);
}
//System.out.println(content.length() + " caractères lus.");
return content.toString();
}
finally{
inputReader.close();
}
} |