List of usage examples for java.net URL getFile
public String getFile()
From source file:Main.java
public static void main(String[] args) throws Exception { String pageAddr = "http://www.google.com/index.htm"; URL url = new URL(pageAddr); String websiteAddress = url.getHost(); String file = url.getFile(); Socket clientSocket = new Socket(websiteAddress, 80); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); OutputStreamWriter outWriter = new OutputStreamWriter(clientSocket.getOutputStream()); outWriter.write("GET " + file + " HTTP/1.0\r\n\n"); outWriter.flush();/*w ww. j a va 2 s. c om*/ BufferedWriter out = new BufferedWriter(new FileWriter(file)); boolean more = true; String input; while (more) { input = inFromServer.readLine(); if (input == null) more = false; else { out.write(input); } } out.close(); clientSocket.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { URL u = new URL("http://www.yourserver.com:80/abc/demo.htm"); System.out.println("The URL is " + u); System.out.println("The file part is " + u.getFile()); }
From source file:Main.java
public static void main(String args[]) throws Exception { URL u = new URL("http://www.yourserver.com:80/abc/demo.htm"); System.out.println("The URL is " + u); System.out.println("The file part is " + u.getFile()); u.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.1.1.10", 10))); }
From source file:Main.java
public static void main(String[] argv) throws Exception { URL url = new URL("http://hostname:80/index.html#_top_"); String protocol = url.getProtocol(); // http String host = url.getHost(); // hostname int port = url.getPort(); // 80 String file = url.getFile(); // index.html String ref = url.getRef(); // _top_ }
From source file:MainClass.java
public static void main(String args[]) throws Exception { URL hp = new URL("http://www.java2s.com"); System.out.println("Protocol: " + hp.getProtocol()); System.out.println("Port: " + hp.getPort()); System.out.println("Host: " + hp.getHost()); System.out.println("File: " + hp.getFile()); System.out.println("Ext:" + hp.toExternalForm()); }
From source file:com.floreantpos.report.ReportUtil.java
public static void main(String[] args) { URL resource = ReceiptPrintService.class.getResource("/printerlayouts/ticket-receipt.jrxml"); //$NON-NLS-1$ String externalForm = resource.getFile(); PosLog.info(ReportUtil.class, resource.getProtocol()); PosLog.info(ReportUtil.class, externalForm); }
From source file:de.oth.keycloak.TestRun.java
public static void main(String[] args) { try {/*from w w w.j a v a2 s. com*/ String server = "http://localhost:8888/auth"; String realm = "master"; String user = "keycloak_admin"; String pwd = "k6ycloakAdmin"; String clientStr = "admin-cli"; String secret = null; String initFileStr = "conf/test_init1.json"; File initFile = new File(initFileStr); if (!initFile.isFile()) { URL url = TestRun.class.getClassLoader().getResource(initFileStr); if (url != null) { initFile = new File(url.getFile()); if (!initFile.isFile()) { log.error("init file does not exist: " + initFile); System.exit(1); } } else { log.error("init file does not exist: " + initFile); System.exit(1); } } Keycloak keycloak = (secret == null) ? Keycloak.getInstance(server, realm, user, pwd, clientStr) : Keycloak.getInstance(server, realm, user, pwd, clientStr, secret); ObjectMapper mapper = new ObjectMapper(); RealmsConfig realmsConfig = mapper.readValue(initFile, RealmsConfig.class); if (realmsConfig != null) { List<RealmConfig> realmList = realmsConfig.getRealms(); if (realmList == null || realmList.isEmpty()) { log.error("no realms config found 1"); return; } for (RealmConfig realmConf : realmList) { InitKeycloakServer.addRealm(keycloak, realmConf); } } else log.error("no realms config found 2"); } catch (Exception e) { log.error(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); System.exit(1); } }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL(args[0]); System.out.println("URL is " + url.toString()); System.out.println("protocol is " + url.getProtocol()); System.out.println("authority is " + url.getAuthority()); System.out.println("file name is " + url.getFile()); System.out.println("host is " + url.getHost()); System.out.println("path is " + url.getPath()); System.out.println("port is " + url.getPort()); System.out.println("default port is " + url.getDefaultPort()); System.out.println("query is " + url.getQuery()); System.out.println("ref is " + url.getRef()); }
From source file:com.yarsquidy.x12.example.exampleSpringParseX12FileOne.java
public static void main(String[] args) { X12 x12 = null;/*from ww w .j a v a2 s .c o m*/ Resource xmlResource = new FileSystemResource("./target/classes/cf/appContext_835_004010X091.xml"); BeanFactory factory = new XmlBeanFactory(xmlResource); Cf cf = (Cf) factory.getBean("bean_X12"); Double totalChargeAmount = 0.0; URL url = exampleSpringParseX12FileOne.class.getClass() .getResource("/org/pb/x12/example/example835One.txt"); File f1 = new File(url.getFile()); Parser parser = new X12Parser(cf); try { x12 = (X12) parser.parse(f1); // calculate the total charge amount List<Loop> loops = x12.findLoop("2100"); for (Loop loop : loops) { for (Segment s : loop) { if (s.getElement(0).equals("CLP")) { totalChargeAmount = totalChargeAmount + Double.parseDouble(s.getElement(3)); } } } System.out.println("Total Charged Amount = " + totalChargeAmount.toString()); // calculate the total charge amount - alternate method totalChargeAmount = 0.0; List<Segment> segments = x12.findSegment("CLP"); for (Segment s : segments) { totalChargeAmount = totalChargeAmount + Double.parseDouble(s.getElement(3)); } System.out.println("Total Charged Amount = " + totalChargeAmount.toString()); } catch (Exception e1) { e1.printStackTrace(); } }
From source file:ParseURL.java
public static void main(String[] args) throws Exception { URL aURL = new URL("http://java.sun.com:80/docs/books/" + "tutorial/index.html#DOWNLOADING"); System.out.println("protocol = " + aURL.getProtocol()); System.out.println("host = " + aURL.getHost()); System.out.println("filename = " + aURL.getFile()); System.out.println("port = " + aURL.getPort()); System.out.println("ref = " + aURL.getRef()); }