Una vez tenemos el documento un array de bytes podremos hacer lo que queramos con él.
public static byte[] leerDocumento(URL url) throws IOException { URLConnection connection = url.openConnection(); InputStream in = null; try { in = connection.getInputStream(); } catch (FileNotFoundException e) { return null; } catch (ConnectException e) { e.printStackTrace(); return null; } int contentLength = connection.getContentLength(); ByteArrayOutputStream tmpOut; if (contentLength != -1) { tmpOut = new ByteArrayOutputStream(contentLength); } else { tmpOut = new ByteArrayOutputStream(16384); } byte[] buf = new byte[512]; while (true) { int len = in.read(buf); if (len == -1) { break; } tmpOut.write(buf, 0, len); } in.close(); tmpOut.close(); byte[] array = tmpOut.toByteArray(); return array; }
$file = fopen("filename.ext", "rb"); $text = ''; while (!feof($file)) { $text .= fread($file, 8192); } fclose($file);