Search
Sponsors
Sponsors

Archive for the ‘Internet’ Category

Download a forex quote

Thursday, August 25th, 2011

 

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);
        }

    }
}

Download a web page

Thursday, August 25th, 2011

 

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
* Main.java
*
* @author www.javadb.com
*/
public class Main {
   
    /**
     * Reads a web page into a StringBuilder object
     * and prints it out to console along with the
     * size of the page.
     */
    public void getWebSite() {
       
        try {
           
            URL url = new URL("http://www.google.com");
            URLConnection urlc = url.openConnection();
           
            BufferedInputStream buffer = new BufferedInputStream(urlc.getInputStream());
           
            StringBuilder builder = new StringBuilder();
            int byteRead;
            while ((byteRead = buffer.read()) != -1)
                builder.append((char) byteRead);
           
            buffer.close();
           
            System.out.println(builder.toString());
            System.out.println("The size of the web page is " + builder.length() + " bytes.");
           
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    /**
     * Starts the program
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Main().getWebSite();
    }
}

Open a url in browser

Thursday, August 25th, 2011

 

Intent viewIntent = new Intent("android.intent.action.VIEW",Uri.parse("http://java.codentuts.com")); 
startActivity(viewIntent);

Translate