2014-11-05 54 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