We would like to know how to retrieve value from url.
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; /*from w w w .j a v a 2 s . c o m*/ public class Main { public static void main(String... args) throws IOException { URL url = new URL("http://java2s.com"); InputStream is = url.openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(); String line; while ((line = br.readLine()) != null) sb.append(line + System.lineSeparator()); br.close(); System.out.print(sb.toString()); } }
The code above generates the following result.