简体   繁体   中英

Save file to internal storage in Android

I want to make a simple Android application which will make user write text and when he presses on save button I'll get the text from text area and create folder then save file into folder in the storage. I did that but in external storage and here's my code

String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/newfolder";
                File f = new File(path);
                f.mkdir();
                PrintWriter pw = new PrintWriter(path + "/" + txt_name.getText() + ".txt");
                pw.write(main_txt.getText().toString());
                pw.close();

This code runs well but it runs only on devices which have an external memory card, so I want to do the same but save file on internal storage for device to make this code run on any device, how can I save file into internal storage?

No.

Your code saves to external memory which is build into the phone.

Your code has nothing to do with a removable micro SD card.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM