Read a file from the internet Tag(s): NetworkingIO
About cookies on this site
We use cookies to collect and analyze information on site performance and usage,
to provide social media features and to enhance and customize content and advertisements.
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
public class NetUtils {
private NetUtils() {}
public static String getTextContent(URL url) throws IOException {
Scanner s = new Scanner(url.openStream()).useDelimiter("\\Z");;
String content = s.next();
return content;
}
public static void main(String[] args) throws IOException {
URL url = new URL("http://www.rgagnon.com/varia/copyrightnotice.txt");
System.out.println(NetUtils.getTextContent(url));
}
}