List of usage examples for java.net URL URL
public URL(String spec) throws MalformedURLException
From source file:URLEquality.java
public static void main(String args[]) { try {/* w w w .jav a 2s .c o m*/ URL sunsite = new URL("http://www.java2s.com"); URL helios = new URL("http://www.demo2s.com"); if (sunsite.equals(helios)) { System.out.println(sunsite + " is the same as " + helios); } else { System.out.println(sunsite + " is not the same as " + helios); } } catch (MalformedURLException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String args[]) throws Exception { URL url = new URL("http://www.google.com"); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); InputStream inStrm = httpCon.getInputStream(); System.out.println("\nContent at " + url); int ch;/*from w ww . j a v a2 s . c o m*/ while (((ch = inStrm.read()) != -1)) System.out.print((char) ch); inStrm.close(); }
From source file:MainClass.java
public static void main(String[] a) throws Exception { URL url = new URL("http://www.yourdomain.com/form.jsp"); URLConnection connection = url.openConnection(); connection.setDoOutput(true);//from ww w .ja va 2 s .com PrintWriter out = new PrintWriter(connection.getOutputStream()); out.println("firstName=Joe"); out.println("lastName=Average"); out.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://localhost:1776"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line;// w ww. j ava 2s. c om while ((line = in.readLine()) != null) { System.out.println(line); } in.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { URL url = new URL("http://hostname:80/index.html"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String str;//from ww w . j av a2s. co m while ((str = in.readLine()) != null) { System.out.println(str); } in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { URLConnection connection = new URL("http://java.net").openConnection(); String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next(); }
From source file:MainClass.java
public static void main(String[] args) { try {//w w w . j a v a2s . com URL url = new URL("file:youraudiofile.wav"); AudioClip ac = Applet.newAudioClip(url); ac.play(); System.out.println("Press any key to exit."); System.in.read(); ac.stop(); } catch (Exception e) { System.out.println(e); } }
From source file:Main.java
License:asdf
public static void main(String[] argv) throws Exception { URLConnection conn = new URL("http://www.yourserver.com").openConnection(); conn.setDoInput(true);// w w w. j a v a2 s. c o m conn.setRequestProperty("Authorization", "asdfasdf"); conn.connect(); InputStream in = conn.getInputStream(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { URL url = new URL("http://hostname:80"); URLConnection conn = url.openConnection(); for (int i = 0;; i++) { String headerName = conn.getHeaderFieldKey(i); String headerValue = conn.getHeaderField(i); if (headerName == null && headerValue == null) { break; }// w w w.ja v a2s . c om if ("Set-Cookie".equalsIgnoreCase(headerName)) { String[] fields = headerValue.split(";\\s*"); for (int j = 1; j < fields.length; j++) { if ("secure".equalsIgnoreCase(fields[j])) { System.out.println("secure=true"); } else if (fields[j].indexOf('=') > 0) { String[] f = fields[j].split("="); if ("expires".equalsIgnoreCase(f[0])) { System.out.println("expires" + f[1]); } else if ("domain".equalsIgnoreCase(f[0])) { System.out.println("domain" + f[1]); } else if ("path".equalsIgnoreCase(f[0])) { System.out.println("path" + f[1]); } } } } } }
From source file:MainClass.java
public static void main(String[] args) { try {/* ww w . ja va 2 s.com*/ URLConnection uc = new URL("http://www.demo2s.com").openConnection(); System.out .println("Will retrieve file if it's been modified since " + new Date(uc.getIfModifiedSince())); uc.setIfModifiedSince(System.currentTimeMillis()); System.out .println("Will retrieve file if it's been modified since " + new Date(uc.getIfModifiedSince())); } catch (Exception e) { System.err.println(e); } }