【发布时间】:2018-02-19 15:42:06
【问题描述】:
我正在尝试使用以下代码从目录中选择 pdf 并读取其内容,但它不起作用
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
startActivityForResult(i, PICKFILE_RESULT_CODE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
switch(requestCode) {
case PICKFILE_RESULT_CODE:
if(resultCode==RESULT_OK){
// String filePath = data.getData().getPath();
// textViewFilePath.setText("File : " + filePath);
// readFromPdf(filePath);
StringBuilder text = new StringBuilder();
String filePath = data.getDataString();
try {
BufferedReader br = new BufferedReader(new FileReader(new File(filePath)));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('n');
}
scanResults.setText(text + ".....");
}
catch (IOException e) {
//You'll need to add proper error handling here
e.printStackTrace();
}
}
break;
}
}
我遇到了异常
java.io.FileNotFoundException: 内容:/com.android.providers.downloads.documents/document/2295:打开 失败:ENOENT(没有这样的文件或目录)
【问题讨论】:
标签: android