List of usage examples for java.net URL URL
public URL(String spec) throws MalformedURLException
From source file:Play.java
public static void main(String args[]) { try {/*from ww w .ja v a 2 s .c o m*/ // Loop URL url = new URL("http://java.sun.com/applets/other/Hangman/audio/whoopy.au"); AudioClip clip = Applet.newAudioClip(url); clip.loop(); Thread.sleep(5000); //Play File file = new File("bark.wav"); clip = Applet.newAudioClip(file.toURL()); clip.play(); Thread.sleep(500); System.exit(0); } catch (InterruptedException e) { } catch (MalformedURLException e) { } }
From source file:MainClass.java
public static void main(String[] args) { try {//from w w w . j ava 2s . co m URL u = new URL("http://www.java2s.com"); OutputStream out = new FileOutputStream("test.htm"); InputStream in = u.openStream(); DTD html = DTD.getDTD("html"); System.out.println(html.getName()); in.close(); out.flush(); out.close(); } catch (Exception e) { System.err.println("Usage: java PageSaver url local_file"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedImage inputFile = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); for (int x = 0; x < inputFile.getWidth(); x++) { for (int y = 0; y < inputFile.getHeight(); y++) { int rgba = inputFile.getRGB(x, y); Color col = new Color(rgba, true); col = new Color(255 - col.getRed(), 255 - col.getGreen(), 255 - col.getBlue()); inputFile.setRGB(x, y, col.getRGB()); }// w ww . j av a 2s. c o m } File outputFile = new File("invert.png"); ImageIO.write(inputFile, "png", outputFile); }
From source file:MainClass.java
public static void main(String[] args) { URL u;/*from w ww . ja va 2 s.co m*/ URLConnection uc; try { u = new URL("http://www.java2s.com"); try { uc = u.openConnection(); if (uc.getUseCaches()) { uc.setUseCaches(false); } } catch (IOException e) { System.err.println(e); } } catch (MalformedURLException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] argv) { Map<String, URL> urlMap = new HashMap<String, URL>(); try {//from ww w . ja v a 2 s . co m urlMap.put("java", new URL("http://www.java2s.com")); } catch (MalformedURLException e) { } String s = urlMap.get("java").getHost(); }
From source file:MainClass.java
public static void main(String args[]) { URL u;// w w w.ja v a 2 s . com URLConnection uc; try { u = new URL("http://www.java2s.com/"); try { uc = u.openConnection(); System.out.println(uc.getURL()); } catch (IOException e) { System.err.println(e); } } catch (MalformedURLException e) { System.err.println(e); } }
From source file:MainClass.java
public static void main(String args[]) { try {/*from ww w . j a va 2 s.c om*/ URL root = new URL("http://"); saveBinaryFile(root); } catch (MalformedURLException e) { System.err.println("not URL I understand."); } }
From source file:MainClass.java
public static void main(String[] args) { try {/*from w w w . j av a2s.com*/ URL url = new URL("http://www.java2s.com"); System.out.println("URL is " + url.toString()); System.out.println("authority is " + url.getAuthority()); System.out.println("path is " + url.getPath()); System.out.println("default port is " + url.getDefaultPort()); System.out.println("query is " + url.getQuery()); System.out.println("ref is " + url.getRef()); } catch (IOException e) { e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); URL url = new URL("https://www.verisign.com/"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line;// w w w . j ava 2s . com while ((line = in.readLine()) != null) { System.out.println(line); } in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String s;// ww w .j a v a2 s.c om s = "http://www.y.com/authTest"; URL url = new URL(s); URLConnection urlc = url.openConnection(); Map<String, List<String>> hf = urlc.getHeaderFields(); for (String key : hf.keySet()) System.out.println(key + ": " + urlc.getHeaderField(key)); System.out.println(((HttpURLConnection) urlc).getResponseCode()); }