Download forex quote for yahoo using java


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4.  
  5. public class ForexTest {
  6. public void getRate() {
  7. try {
  8. URL url = new URL("http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=EURUSD=X");
  9. URLConnection urlc = url.openConnection();
  10.  
  11. BufferedReader reader = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
  12.  
  13. String line;
  14.  
  15. while ((line = reader.readLine()) != null) {
  16. sb.append(line);
  17. }
  18. System.out.println(sb);
  19.  
  20.  
  21. } catch (MalformedURLException ex) {
  22. ex.printStackTrace();
  23. } catch (IOException ex) {
  24. ex.printStackTrace();
  25. }
  26. }
  27.  
  28. public static void main(String[] args) throws Exception {
  29. ForexTest ft = new ForexTest();
  30. while (true) {
  31. ft.getRate();
  32. Thread.sleep(10000);
  33. }
  34.  
  35. }
  36. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.