java download file from url to string

Java
public static String URLReader(URL url) throws IOException {
    StringBuilder sb = new StringBuilder();
    String line;
 
    InputStream in = url.openStream();
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while ((line = reader.readLine()) != null) {
            sb.append(line).append(System.lineSeparator());
        }
    } finally {
        in.close();
    }
 
    return sb.toString();
}

Source

Also in Java: