簡體   English   中英

Java 來自 URL 文本文件的單行掃描儀

[英]Java One-liner Scanner from URL Text file

在 java 中,我需要從“http://www.mysite.com/text.txt”獲取什么代碼到一個掃描儀,該掃描儀以盡可能少的行解析站點中包含的結果文本。

Scanner sc = new Scanner(new URL("http://www.mysite.com/text.txt").openStream());
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();

參考

取自這里,未經測試

URLConnection connection = new URL("http://www.mysite.com/text.txt").openConnection();
String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next();

一行代碼中的HTTP GET :(使用 Java 8)

String doc = new Scanner(new URL(strUrl).openStream(), "UTF-8").useDelimiter("\\A").next();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM