Android: 将文本文件存储在 android 设备的内存中而不是外部存储卡中?

Android: Storing text file in android device's internal memory not in external memory card?

我尝试将文本文件存储在设备的 phone 内存中,它正在与支持外部插槽的设备一起使用。但它不适用于 android phone没有外部插槽。(例如三星 S6 Edge)。

这是我的代码:

public void AfterSaveClick() {

        OutputStream fOut = null;

        try {

            Toast.makeText(MainActivity.this, "Start",Toast.LENGTH_SHORT).show();
            //device basic path(phone memory)
            File root = new File(Environment.getExternalStorageDirectory()
                    + File.separator + "Log_Folder" + File.separator);
            root.mkdirs();
            File phoneMemoryTextMainDirectory = new File(root, "samples.txt");

            FileWriter writer = new FileWriter(phoneMemoryTextMainDirectory);
            writer.append("Hello");
            writer.flush();
            writer.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    } 

我认为你应该先检查设备是否有外部存储,你可以使用这样的东西:

Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

如果设备有外部存储,则使用您已有的路径,否则您应该在 phone 的内部存储器中添加另一个路径。