i have a folder inside com.example.myapplication called files inside it there is a file text file called users how to read and write in java android studio
i tried bufferread read = new bufferread(new fileread(filename)))
i have a folder inside com.example.myapplication called files inside it there is a file text file called users how to read and write in java android studio
i tried bufferread read = new bufferread(new fileread(filename)))
2
Answers
Here is an example to read a file:
This to write to a file instead:
How to read and write to a text file in Android Studio
Here’s how you can read and write to a text file called "users" inside the "files" folder of your "com.example.myapplication" project in Android Studio:
Reading:
Writing:
Note:
The getFilesDir() method gets the directory where your app can store private files.
Use try-with-resources block to automatically close the reader and writer.
You can read and write multiple lines of text using a loop.
Make sure to handle exceptions properly.
Additional resources:
Android developer documentation on file storage: https://developer.android.com/reference/java/io/File
Stack Overflow question on reading and writing to a file: Read/Write String from/to a File in Android
Regarding your previous attempt:
The code you provided, bufferread read = new bufferread(new fileread(filename))), is incorrect. It should be:
You misspelled BufferedReader and used fileread instead of FileReader. Remember, class names are case-sensitive in Java.