在 sd 卡上创建一个 txt 文件,但我找不到它

creating a txt file on sd card but i cant find it

我想在我的 SD 卡上创建一个文本文件。我找到了很多代码示例并尝试了它们。 None 他们响应了任何异常,所以我希望他们能工作,但是当我浏览我的 sdcard 时,我找不到文本文件。 这是我正在尝试的尝试:

 try {
            File sdcard = Environment.getExternalStorageDirectory();

            File myFile = new File(sdcard,"text.txt");
            myFile.createNewFile();

            FileOutputStream fOut = new FileOutputStream(myFile);
            OutputStreamWriter myOutWriter =
                    new OutputStreamWriter(fOut);
            myOutWriter.append(encodedString); // this is a long string
            myOutWriter.close();
            fOut.close();
            Toast.makeText(getBaseContext(),
                    "written to: "+myFile.getAbsolutePath(),
                    Toast.LENGTH_SHORT).show();

这是 Toast 告诉我的内容: 我的期望:"written to: /sdcard/text.txt" 我得到的是:"written to: /storage/emulated/0/text.txt"

为什么应用程序没有按预期将文本文件保存到 SD 卡上,我需要更改什么才能做到这一点?

getExternalStorageDirectory() 不需要 return /sdcard 目录。看这里Environment.getExternalStorageDirectory does not return the path to the removable storage