Yahoo Currency API Java多种货币请求

时间:2015-07-09 17:59:23

标签: java api currency yahoo finance

我无法从雅虎一次抓取多种货币,代码产生了 第一次请求,但不是第二次请求。

public double getRate(String from1, String to1, String from2, String to2) {

    try {
        URL url = new URL("http://quote.yahoo.com/d/quotes.csv?f=l1&s=" + from1 + to1 + "=X," + from2 + to2 + "=X");
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));

        String line = reader.readLine();
        if (line.length() > 0) {
            return Double.parseDouble(line);
        }

        reader.close();
    } catch (IOException | NumberFormatException e) {
        System.out.println(e.getMessage());
    }

    return 0;
}

任何想法都会受到赞赏。

最佳

0 个答案:

没有答案