File dir = Environment.getExternalStorageDirectory (); File Assistant = new file ("/mnt/sdcard/Sample.pdf"); try {InputStream fis = new FileInputStream (assist);
long length = assist.length(); if (length > Integer.MAX_VALUE) { Log.e("MainActivity", "cannnottt readddd"); } byte[] bytes = new byte[(int) length]; int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = fis.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead; } File data = new File(dir, "mydemo.pdf"); OutputStream op = new FileOutputStream(data); op.write(bytes); }catch (Exception ex){ Log.e("MainActivity", ""+ex.getMessage()) }
source share