【发布时间】:2018-01-20 22:36:02
【问题描述】:
我需要从 sdcard 中选择一个 pdf 并将其转换为字节数组。我不想表现出来。我搜索了很多,但这个问题没有答案。
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_MAGAZINE_FILE && resultCode == RESULT_OK && data != null) {
// Let's read picked image data - its URI
Uri uri = data.getData();
System.out.println(uri);
System.out.println(uri.getPath());
File file = new File(uri.getPath());
//init array with file length
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);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我收到了这个错误:
java.io.FileNotFoundException: /document/primary:myfile.pdf: open failed: ENOENT (No such file or directory)
【问题讨论】:
标签: android arrays pdf android-intent