【问题标题】:from a file into an array of String []从一个文件到一个字符串数组[]
【发布时间】:2014-12-29 19:28:52
【问题描述】:

我有一个 小型 服务器,其中包含 文本文件,它可能类似于:

http://127.0.0.1:59777/smb/192.168.0.250/Files/Interstellar.mp4
http://127.0.0.1:59777/smb/192.168.0.250/Files/уаау.mp4
http://127.0.0.1:59777/smb/192.168.0.250/Files/possible.mp4

在我的程序中有listView 用于构建应从文件中的列表构建的用途列表,所以我有 2 个问题。 1) 是否可以通过 URL 访问文件?如果是这样,那么问题编号 2 。 2)尽快通过URL从文件中读取数据到String[]数组中

        private static String[] dataObjects = new String[]{ "Text #1",
        "Text #2",
        "Text #3","Text #4","Text #5" };

路人?

【问题讨论】:

  • 第一:到目前为止你尝试了什么?第二: localhost 就是 localhost - 设备 /emulator 本身。
  • 1) Is it possible to access the file via URL? 是的。 2) as soon as possible via the URL to read data from a file into an array of String []是的
  • @Simon,可以给出一个很简单的示例代码,如果不难,那就很plagodaren好了,或者链接。

标签: android list file android-listview android-file


【解决方案1】:

简而言之:

  • 在网页视图中加载您的网址
  • 将两个客户端添加到您的 web 视图中,例如 there
  • 用 html.split("\n"); 分割你的 html;

【讨论】:

    【解决方案2】:
    try {
        URL url = new URL("www.yoursite.com/file.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) {
        in.close();
    } catch (IOException e) {
        in.close();
    }
    

    并查看此链接以将其放入列表中:
    http://sampleprogramz.com/android/listviewwebservice.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-04
      • 1970-01-01
      • 2023-01-16
      • 2023-02-04
      • 2018-05-07
      • 1970-01-01
      • 1970-01-01
      • 2013-05-15
      相关资源
      最近更新 更多