我在网站上提供了数据,如下图所示:
该网站提供了一些参数的值,这些参数每隔一段时间就会更新。现在我想根据Android应用程序中的列名和行号来检索这些数据,我知道如何打开http连接。但不幸的是,我不知道应该从哪里开始以及如何读取图像中提供的数据。
除非您有特殊的数据源要处理,否则您必须阅读网站的内容然后手动处理它。这是java 教程中有关如何从 URL 连接中读取的链接。
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://www.oracle.com/");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
编辑:
如果您使用代理,您还应该设置这些系统属性(设置为适当的值):
System.setProperty("http.proxyHost", "3.182.12.1");
System.setProperty("http.proxyPort", "1111");
如果数据只是明文并且表格的格式没有改变,您可以解析整个表格,例如在阅读“------- ...”行后,您可以使用扫描仪解析值:
Scanner s;
while ((inputLine = in.readLine()) != null)
{
s = new Scanner(input).useDelimiter(" ");
//Then readthe Values like
value = s.next()); // add all values in a list or array
}
s.close();
您必须解析整个内容。你不能调用网络服务来获取这些数据,或者直接调用属于这个视图的数据库吗?