In java, what code do I need to get from "http://www.mysite.com/text.txt" to a scanner that analyzes the received text contained on the site, as few lines as possible.
URL yahoo = new URL("http://www.yahoo.com/"); BufferedReader in = new BufferedReader( new InputStreamReader( yahoo.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close();
Link
Scanner sc = new Scanner(new URL("http://www.mysite.com/text.txt").openStream());
Taken from here , not verified
URLConnection connection = new URL("http://www.mysite.com/text.txt").openConnection(); String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next();
HTTP GET in one line of code: (using Java 8)
HTTP GET
String doc = new Scanner(new URL(strUrl).openStream(), "UTF-8").useDelimiter("\\A").next();