List of usage examples for java.net URL openStream
public final InputStream openStream() throws java.io.IOException
From source file:MainClass.java
public static void main(String[] args) throws IOException { InputStream in = null;// w ww.j a v a 2s .com try { URL u = new URL("http://www.java2s.com"); in = u.openStream(); for (int c = in.read(); c != -1; c = in.read()) { System.out.write(c); } in.close(); } catch (MalformedURLException ex) { System.err.println("not a URL Java understands."); } finally { if (in != null) in.close(); } }
From source file:Main.java
public static void main(String args[]) throws Exception { Properties props = new Properties(); URL url = ClassLoader.getSystemResource("props.properties"); props.load(url.openStream()); System.out.println("prop1 :\n " + props.get("prop1")); System.out.println("prop2 :\n " + props.get("prop2")); }
From source file:Main.java
public static void main(String args[]) throws Exception { Properties props = new Properties(); URL url = ClassLoader.getSystemResource("myprops.props"); props.load(url.openStream()); System.out.println(props);/*from w ww. j a va 2 s. c om*/ }
From source file:Main.java
public static void main(String args[]) throws Exception { Properties props = new Properties(); URL url = ClassLoader.getSystemResource("props.properties"); props.load(url.openStream()); System.out.println("prop1 :\n " + props.get("prop1")); System.out.println("prop2 :\n " + props.get("prop2")); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL u = new URL("http://www.google.com"); InputStream in = u.openStream(); MessageDigest sha = MessageDigest.getInstance("SHA"); byte[] data = new byte[1024]; int bytesRead = -1; while ((bytesRead = in.read(data)) >= 0) { sha.update(data, 0, bytesRead);//from ww w. j a v a 2 s .c o m } byte[] result = sha.digest(); System.out.println(Arrays.toString(result)); System.out.println(new BigInteger(result)); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { URL u = new URL("http://www.java2s.com"); InputStream in = u.openStream(); in = new BufferedInputStream(in); Reader r = new InputStreamReader(in); int c;/* ww w .j av a2 s .c om*/ while ((c = r.read()) != -1) { System.out.print((char) c); } }
From source file:Main.java
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;/*from www. ja va2 s. co m*/ while ((line = br.readLine()) != null) sb.append(line + System.lineSeparator()); br.close(); System.out.print(sb.toString()); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { Authenticator.setDefault(new DialogAuthenticator()); URL u = new URL("secure url"); InputStream in = u.openStream(); in = new BufferedInputStream(in); Reader r = new InputStreamReader(in); int c;//from www. j av a 2 s.co m while ((c = r.read()) != -1) { System.out.print((char) c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { URL[] urls = { new URL("http://yourserver/small.png") }; for (URL url : urls) { ImageInputStream iis = ImageIO.createImageInputStream(url.openStream()); Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); System.out.println("url= " + url.getPath()); while (readers.hasNext()) { ImageReader read = readers.next(); System.out.println("format name = " + read.getFormatName()); }/* w ww.jav a2 s .c o m*/ System.out.println(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String thisLine;/*ww w. ja va2 s . c o m*/ URL u = new URL("http://www.google.com"); DataInputStream theHTML = new DataInputStream(u.openStream()); while ((thisLine = theHTML.readLine()) != null) { System.out.println(thisLine); } }