如何制作以编程方式下载网络内容特定部分的android应用程序?

问题描述

我在我的项目中工作,需要使用网络内容的特定部分而不是网站的整个数据。 有什么办法可以在android中做到这一点?

解决方法

我更喜欢在使用所需的部分内容后下载整个网络数据。 首先像这样下载数据。

public static void main(String[] args) {
    URL url;
    InputStream is = null;
    BufferedReader br;
    String line;

    try {
        url = new URL("your.website/");
        is = url.openStream();  // throws an IOException
        br = new BufferedReader(new InputStreamReader(is));

        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
    } catch (MalformedURLException mue) {
         mue.printStackTrace();
    } catch (IOException ioe) {
         ioe.printStackTrace();
    } finally {
        try {
            if (is != null) is.close();
        } catch (IOException ioe) {
            // nothing to see here
        }
    }
}

之后,您可以使用来收集所需的数据。