我试图下载一个csv文件,然后需要从中提取信息... 我尝试了以下代码......
URL url=new URL("http://download.finance.yahoo.com/d/quotes.csv?s=INFY.BO&f=sl1d1t1c1ohgv&e=.csv");
HttpURLConnection c=(HttpURLConnection)url.openConnection();
c.setRequestMethod("GET");
c.connect();
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
while ((len1 = is.read(buffer)) != -1)
{
sb.append(buffer);
}
System.out.println("\n\n\nSTRING >>>>>>>>>>>>> "+sb+"\n\n\n");
现在这总是会显示一条错误,表示它意外关闭。
logcat - link
答案 0 :(得分:0)
sb
android.permission.INTERNET
BufferedReader
从字符流中读取。 (此处未使用sb
)
InputStream is = c.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
while ((line = br.readLine()) != null) {
Log.i("msg", new String(line));
}