I'm trying to convert a File to byte array format. The selected actual path is there in the storage, but still its throwing exception as "File Not Found". Can anyone help me to sort out this?
Thanks for your precious time!..
calling file manager
btn_click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 7);
}
});
getting response
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
switch (requestCode) {
case 7:
if (resultCode == RESULT_OK) {
String filePath = data.getData().getPath();
System.out.println("====== path : "+filePath);
File file = new File(filePath);
byte[] bytesArray = new byte[(int) file.length()];
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
fis.read(bytesArray); //read file into bytes[]
fis.close();
System.out.println("====== bytesArray "+bytesArray);
} catch (FileNotFoundException e) {
System.out.println("====== File Not Found.");
e.printStackTrace();
} catch (IOException e) {
System.out.println("====== Error Reading The File. IOException");
e.printStackTrace();
}
}
}
}