List of usage examples for java.net URL URL
public URL(String spec) throws MalformedURLException
From source file:Main.java
public static void main(String[] args) throws Exception { URL yahoo = new URL("http://www.yahoo.com/"); URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine;/*www.j a v a 2s . c om*/ while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { URL u = new URL(args[0]); URLConnection uc = u.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream())); String s = br.readLine();/*w ww . j a v a 2 s . com*/ while (s != null) { System.out.println(s); s = br.readLine(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedImage image = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); System.out.println(image == null); int width = image.getWidth(); int height = image.getHeight(); System.out.println(width + "x" + height); for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { System.out.printf("%04X ", image.getRGB(col, row)); }/*from w w w .j a v a2 s . c o m*/ System.out.println(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { URL url = new URL("jar:file:/c://my.jar!/"); JarURLConnection conn = (JarURLConnection) url.openConnection(); Attributes attrs = conn.getAttributes(); Certificate[] certs = conn.getCertificates(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { URL url = new URL("https://www.server.com"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine;//from w w w . j a v a 2s . co m while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); }
From source file:MainClass.java
public static void main(String args[]) { URL webURL, ftpURL;//from w w w .j av a 2 s. c om try { webURL = new URL("http://www.macfaq.com/vendor.html"); System.out.println(webURL); ftpURL = new URL("ftp://ftp.macfaq.com/pub/"); System.out.println(ftpURL); webURL = new URL("http", "www.macfaq.com", "/vendor.html"); System.out.println(webURL); ftpURL = new URL("ftp", "ftp.macfaq.com", "/pub"); System.out.println(ftpURL); webURL = new URL("http", "www.macfaq.com", 80, "/vendor.html"); System.out.println(webURL); ftpURL = new URL("ftp", "ftp.macfaq.com", 21, "/pub"); System.out.println(ftpURL); } catch (MalformedURLException e) { System.err.println(e); } }
From source file:MainClass.java
public static void main(String args[]) { try {/*from w ww . java 2 s . com*/ URL u = new URL("http://www.java2s.com"); URLConnection uc = u.openConnection(); System.out.println("Content-encoding: " + uc.getContentEncoding()); } catch (MalformedURLException e) { System.err.println("not a URL I understand"); } catch (IOException e) { System.err.println(e); } }
From source file:GetURL.java
public static void main(String args[]) throws Exception { URL url = new URL("http://www.google.com"); InputStream urlstream = url.openStream(); byte[] buffer = new byte[0]; byte[] chunk = new byte[4096]; int count;/*from w ww. j a v a2 s.co m*/ while ((count = urlstream.read(chunk)) >= 0) { byte[] t = new byte[buffer.length + count]; System.arraycopy(buffer, 0, t, 0, buffer.length); System.arraycopy(chunk, 0, t, buffer.length, count); buffer = t; } String filename = (url.getFile()).replace('/', File.separatorChar); File f1 = new File(filename); filename = f1.getName(); FileOutputStream f = null; f = new FileOutputStream(filename); f.write(buffer); f.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.java2s.com/"); URLConnection urlConnection = url.openConnection(); Map<String, List<String>> headers = urlConnection.getHeaderFields(); Set<Map.Entry<String, List<String>>> entrySet = headers.entrySet(); for (Map.Entry<String, List<String>> entry : entrySet) { String headerName = entry.getKey(); System.out.println("Header Name:" + headerName); List<String> headerValues = entry.getValue(); for (String value : headerValues) { System.out.print("Header value:" + value); }//ww w. ja v a2 s . c o m System.out.println(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { HttpURLConnection.setFollowRedirects(false); HttpURLConnection con = (HttpURLConnection) new URL("http://www.google.coom").openConnection(); con.setRequestMethod("HEAD"); System.out.println(con.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM); }