Search
Sponsors
Sponsors

Download a forex quote

 

import java.net.*;
import java.io.*;

public class ForexTest {
    public void getRate() {
        try {
            URL url = new URL("http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=EURUSD=X");
            URLConnection urlc = url.openConnection();

            BufferedReader reader = new BufferedReader(new InputStreamReader(urlc.getInputStream()));

            String line;
            StringBuffer sb = new StringBuffer();

            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            System.out.println(sb);

        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        ForexTest ft = new ForexTest();
        while (true) {
            ft.getRate();
            Thread.sleep(10000);
        }

    }
}

Related posts:

  1. Download a web page   import java.io.BufferedInputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import...
  2. Read a file   import java.net.*; import java.io.*; public class URLReader {    ...
  3. Read a file   File multiUserFile = new File("test.txt"); String line = "";...
  4. Download an image from the internet   //MainActivity.java package com.v3; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection;...
  5. Keyboard input   import java.io.*; public class ReadString {    public static...

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply

Translate