我是靠谱客的博主 虚拟银耳汤,这篇文章主要介绍android uri找不到,尝试从android中的uri读取时找不到文件异常,现在分享给大家,希望可以做个参考。

我想从uri读取一个fileInputStream,但它返回的文件未找到异常

到目前为止,这是我的代码:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType("*/*");

intent.addCategory(Intent.CATEGORY_OPENABLE);

try {

startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);

} catch (android.content.ActivityNotFoundException ex) {

Toast.makeText(getContext(), "Please install a File Manager.", Toast.LENGTH_SHORT).show();

}

public void onActivityResult(int requestCode, int resultCode, Intent data) {

switch (requestCode) {

case FILE_SELECT_CODE:

if (resultCode == RESULT_OK) {

// Get the Uri of the selected file

Uri fileUri = data.getData();

long size = Helper.GetFileSize(getActivity(),fileUri);

File F = new File(fileUri.getPath());

Log.d("File", "File Uri: " + fileUri.toString());

FileInputStream fis;

try {

fis = new FileInputStream(new File(F.getPath()));

}

catch (Exception ex) {

ex.printStackTrace();

}

}

break;

}

super.onActivityResult(requestCode, resultCode, data);

}

最后

以上就是虚拟银耳汤最近收集整理的关于android uri找不到,尝试从android中的uri读取时找不到文件异常的全部内容,更多相关android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(118)

评论列表共有 0 条评论

立即
投稿
返回
顶部