// 3) Get data (show the file contents) String str; iStrm = http.openInputStream(); int length = (int) http.getLength(); if (length != -1) { // Read data in one chunk byte serverData[] = new byte[length]; iStrm.read(serverData); str = new String(serverData); } else // Length not available... { ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
// Read data one character at a time int ch; while ((ch = iStrm.read()) != -1) bStrm.write(ch);
str = new String(bStrm.toByteArray()); bStrm.close(); }
System.out.println("File Contents: " + str);
//----------------------------- // Show connection information //----------------------------- System.out.println("Host: " + http.getHost()); System.out.println("Port: " + http.getPort()); System.out.println("Type: " + http.getType());