Sample code for Android file storage and reading

requirement:

Enter the file name. The file contents are stored in the phone's memory and external memory, and can be read out.

Steps:

1. Create an Android project named cdsavefile

2. Write layout file activity_ main.xml:

3. Write the code mainactivity.java in the main activity:

The fileservice class in the main activity is used to handle the specific operations of the transaction after the button is clicked. The code is as follows:

The code of strings.xml is as follows:

4. Add permissions in androidmanifest.xml

5. The project is deployed on the simulator:

After entering the program:

Save the file on your phone and read it:

Store the file on SD and read:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>