Android Studio – How to Save a File on Internal Storage (Read / Write)




In this tutorial we will learn How to Save a File on Internal Storage Using Android Studio. Also this exmple shows How to read from the saved file and how to write to the saved file.

So lets create a project.

Step 1  – Create new Android project and name your project as WriteToFile .

Step 2 – Add Two buttons , a EditText and TextView in the main activity as shown in the picture below.

Save a File on Internal Storage design

layout/activity_main.xml

MainActivity.java

FileInputStream Class used in the code above can be used as an An input stream that reads bytes from a file.
FileOutputStream Class used in the code above can be used as an An output stream that writes bytes to a file. If the output file exists, it can be replaced or appended to. If it does not exist, a new file will be created

Now run your code and see the following Output:

Save a File on Internal Storage Output- preess wrie button

Save a File on Internal Storage Output- preess read button


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


  • hasif

    error showing like cannot find symbol variable main

  • Leigh Goodwin

    This is a good example. It could be better if you could write to the file and read from it at a later date.