Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java One-liner Scanner from URL Text file

In java, what code do I need to get from "http://www.mysite.com/text.txt" to a Scanner that parses the resulting text contained in the site in as few lines as possible.

like image 613
steve-gregory Avatar asked Dec 02 '22 02:12

steve-gregory


2 Answers

Scanner sc = new Scanner(new URL("http://www.mysite.com/text.txt").openStream());
like image 153
tanyehzheng Avatar answered Dec 08 '22 00:12

tanyehzheng


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();

Reference

  • Reading URL in Java
like image 22
jmj Avatar answered Dec 08 '22 00:12

jmj