【问题标题】:Having issue with InputStreamInputStream 有问题
【发布时间】:2021-01-25 05:03:32
【问题描述】:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try {


        // When an file is picked
        if (requestCode == 3 && resultCode == RESULT_OK && null != data) {

            Uri uri = data.getData();

            InputStream is = getContentResolver().openInputStream(uri);
        }
        else {
            Toast.makeText(this, "You haven't picked any file", Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
        Log.d("EXCEPTION_ERROR",e.toString());
        e.printStackTrace();
    }

}

我试过了。我添加了更多源代码。但是,inputStream 给出了错误。

EXCEPTION_ERROR: java.io.FileNotFoundException: 没有这样的文件或目录

System.err: java.io.FileNotFoundException: 没有这样的文件或目录

System.err:在 android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:151)

乌里:

content://com.android.providers.downloads.documents/document/3356

content://com.android.providers.downloads.documents/document/3331

【问题讨论】:

  • uri的值是多少?或许您应该记录它以便您可以看到它。
  • 我不知道android,但是内容是像文件和http这样的真正的内容类型吗?
  • @NomadMaker uriurl 之间有区别
  • 是的,我知道。对不起,这该死的手机上的拼写检查器找到了我。但是内容是 uri 可接受的方案吗?
  • 没有。只需使用文件应用程序或其他文件管理器应用程序。转到同一个文件并尝试让它打开。

标签: java android stream


【解决方案1】:

我认为问题出在 uris 上。通常如果 uri 以 content:// 开头,这意味着 uri 假设包含在意图中并被发送到其他应用程序。以及其他应用程序如何解析该 uri。 因此,您可以尝试以下方法之一,希望它能奏效。

从此改变

content://com.android.providers.downloads.documents/document/3356

到这里

file://document/3356 //An absolute path for "document/3356" is better like "/storage/emulated/0/document/3356".

或者,从这里

content://com.android.providers.downloads.documents/document/3356

到这里

content://com.android.providers.downloads.file/document/3356

您可以使用Uri.parse() 获取uri 的实例。

Uri uri = Uri.parse("file://document/3356");
Uri uri = Uri.parse("file:///storage/emulated/0/document/3356");
Uri uri = Uri.parse("content://com.android.providers.downloads.file/document/3356");

【讨论】:

    猜你喜欢
    • 2012-07-06
    • 1970-01-01
    • 2011-09-03
    • 2014-07-07
    • 1970-01-01
    • 2015-03-26
    • 2014-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多