Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:如何从文件路径获取文件_Android_Android File - Fatal编程技术网

Android:如何从文件路径获取文件

Android:如何从文件路径获取文件,android,android-file,Android,Android File,我正在我的应用程序中执行文件上载任务。为此,我使用了FileChooseActivity 我从文档中编写了这段代码 Intent intent = new Intent(_context, FileChooserActivity.class); Toast.makeText(_context, "inside attachment", Toast.LENGTH_SHORT).show(); ((Activit

我正在我的应用程序中执行文件上载任务。为此,我使用了FileChooseActivity

我从文档中编写了这段代码

Intent intent = new Intent(_context, FileChooserActivity.class);
            Toast.makeText(_context, "inside attachment",
                    Toast.LENGTH_SHORT).show();
            ((Activity) _context).startActivityForResult(intent,
                    FILE_CHOOSER);

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == FILE_CHOOSER) && (resultCode == RESULT_OK)) {
    String fileSelected = data.getStringExtra(Constants.KEY_FILE_SELECTED);
    Toast.makeText(this, "file selected "+fileSelected, Toast.LENGTH_SHORT).show();
}                    
}
实际上,这里我得到的是fileSelected中的文件路径。但我想将所选文件存储在文件对象中。我该怎么办?我可以将此路径转换为文件吗?请帮我举个例子。

文件File=新文件(filePath)