i want convert PDF file to byte array in (onActivityResult) I tried several different ways but it didn't work Please answer if anyone knows.
Update :
case 1212 : if (resultCode == RESULT_OK){ Uri uri = data.getData(); File file = new File(uri.getPath()); int size = (int) file.length(); byte[] bytes = new byte[size]; try { BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file)); buf.read(bytes, 0, bytes.length); buf.close(); } catch (FileNotFoundException e) { Toast.makeText(getApplicationContext(),"FileNotFound",Toast.LENGTH_LONG).show(); e.printStackTrace(); } catch (IOException e) { Toast.makeText(getApplicationContext(),"IOException",Toast.LENGTH_LONG).show(); e.printStackTrace(); } }else Toast.makeText(getApplicationContext(),"خطا!",Toast.LENGTH_LONG).show(); this code show FileNotFound Toast
uri.getPath()won't return you the file path usually. Use developer.android.com/reference/android/content/… to open stream from Uri, and then read it into byte array.but it didn't workhow exactly?