簡體   English   中英

在android中讀取遠程文本文件

[英]Read remote text file in android

我對android開發很新,所以請原諒我的無知。 我需要能夠以15分鍾的間隔從遠程網頁上讀取一些文本。 網頁本身只包含一個沒有html標簽或格式的單詞。 如果有人可以指出我正確的方向,我會很感激。

謝謝

當然,請嘗試以下方法

try {
    // Create a URL for the desired page
    URL url = new URL("yoursite.com/thefile.txt");

    // Read all the text returned by the server
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    String str = in.readLine();
    in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}

您可能希望將“in.close()”放在finally {}子句中,以確保它始終關閉

暫無
暫無

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

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