Cant find the saved data to text file in internal storage, How to save file in internal storage android studio?

拟墨画扇 提交于 2020-12-12 04:04:46

问题


I want to create a text file on my android phone and write some text into it.
When I click on the button it says saved to /data/user/0/com.example.savetotextfile/files/example.txt
But I can't find these folders.
Most apps are in Device storage > Android > data, but the apps that I created myself are not in there.
Am I missing a permission?
I don't want to write to an sd card.

public class MainActivity extends AppCompatActivity {

    private static final String FILE_NAME = "example.txt";

    EditText editText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editText = findViewById(R.id.editText);
    }

    public void save(View v) {
        String text = editText.getText().toString();
        FileOutputStream fos = null;

        try {
            fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
            fos.write(text.getBytes());

            editText.getText().clear();
            Toast.makeText(this, "Saved to" + getFilesDir() + "/" + FILE_NAME, Toast.LENGTH_LONG).show();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

回答1:


If you want to see file saved in internal storage you cannot just see through file manager. (Note your phone should be rooted if you want to see that directly)

Follow these steps to view files saved in internal storage.

1) Attach the device to your laptop/computer.

2) Open the android studio.

3) Now in the right extreme of android studio you will this option Device File Manager.

4) Double click on data folder then again double click on data folder

5) find the package name of your app like com.example.yourapp and double click on it.

6) double click on files folder under the package name of your app you want to see the internal storage files.



来源:https://stackoverflow.com/questions/61169547/cant-find-the-saved-data-to-text-file-in-internal-storage-how-to-save-file-in-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!