Skip to content

Instantly share code, notes, and snippets.

@hanigamal
Created June 2, 2012 13:35
Show Gist options
  • Save hanigamal/2858458 to your computer and use it in GitHub Desktop.
Save hanigamal/2858458 to your computer and use it in GitHub Desktop.
Remote PDF
try {
URL u = new URL("http://hanigamal.net/resume.pdf");
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String fileName = Environment.getExternalStorageDirectory().getAbsolutePath();
FileOutputStream f = new FileOutputStream(new File(fileName,"my.pdf"));
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ( (len1 = in.read(buffer)) > 0 ) {
f.write(buffer,0, len1);
}
f.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment