2014-11-05 51 views

回答

0
BufferedReader in = null; 
try { 
    String urlStr = "https://blockchain.info/de/q/24hrprice"; 
    URL url = new URL(urlStr); 
    URLConnection con = url.openConnection(); 
    in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8")); 
    String input; 
    while ((input = in.readLine()) != null) { 
    System.out.println(input); //you can parse input as Integer or Double now 
    } 

} catch (MalformedURLException ex) { 
    System.err.println(ex); 
} catch (IOException ex) { 
    System.err.println(ex); 
} finally { 
    try { 
    in.close(); 
    } catch (Exception ex) { 
    System.err.println(ex); 
    } 
} 
+0

感謝您的快速響應!當我嘗試使用您的代碼時,出現以下錯誤: 新的URL(urlStr)錯誤:java.net.malformedurlexception url.openConnection,con.getInputStream,in.readLine和in.close錯誤:java.io. IOException 我在做什麼錯? – user3254327 2014-11-05 11:57:18

+0

我不知道...它適用於我。你有沒有複製我更新的答案?我只是更改了urlStr,以包含「https://」,而我並沒有在第一個版本中使用它。 – vefthym 2014-11-05 12:00:50

+0

等等...你把它放在try-catch塊嗎? – vefthym 2014-11-05 12:02:05