java download file from url to string

Solutions on MaxInterview for java download file from url to string by the best coders in the world

showing results for - "java download file from url to string"
Juan Esteban
01 Mar 2016
1public static String URLReader(URL url) throws IOException {
2    StringBuilder sb = new StringBuilder();
3    String line;
4 
5    InputStream in = url.openStream();
6    try {
7        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
8        while ((line = reader.readLine()) != null) {
9            sb.append(line).append(System.lineSeparator());
10        }
11    } finally {
12        in.close();
13    }
14 
15    return sb.toString();
16}
17