tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Google Guava > IO > Read from URL

Read from URL 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Resources.toString() API.

File Name  :  
com/bethecoder/tutorials/guava/io_tests/ReadFromURLTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.guava.io_tests;

import java.io.IOException;
import java.net.URL;

import com.google.common.base.Charsets;
import com.google.common.io.Resources;

public class ReadFromURLTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    URL url = new URL("http://finance.google.com/finance/info?client=ig&q=NASDAQ:MSFT");
    String urlContent = Resources.toString(url, Charsets.UTF_8);
    System.out.println(urlContent);
  }
}
   

It gives the following output,

// [
{
"id": "358464"
,"t" : "MSFT"
,"e" : "NASDAQ"
,"l" : "24.79"
,"l_cur" : "24.79"
,"s": "2"
,"ltt":"4:00PM EST"
,"lt" : "Nov 22, 4:00PM EST"
,"c" : "-0.21"
,"cp" : "-0.84"
,"ccol" : "chr"
,"el": "24.76"
,"el_cur": "24.76"
,"elt" : "Nov 22, 7:59PM EST"
,"ec" : "-0.03"
,"ecp" : "-0.12"
,"eccol" : "chr"
,"div" : "0.20"
,"yld" : "3.23"
}
]


                    Print

   



Books Recommendation

 
 
bl  br