0

Here's what I need to happen: I've got a text file with some values in them that I need to read (Let's say it is example.txt). I need to read that file like i would using ex. FileInputStream or BufferedReader). How would I go about doing it?

PS - This is what I tried doing, but it didn't help. I would always get an error saying the file has to be .xml

Nick
  • 45
  • 8
  • Put the file [in `assets` in your module](https://stackoverflow.com/a/18302624/115145). Then, use `AssetManager` and its `open()` method to get an `InputStream` on the asset. – CommonsWare Jul 26 '20 at 18:38
  • @CommonsWare Thank you, that works! Is there any way that I can write to that file? – Nick Jul 26 '20 at 19:16
  • "Is there any way that I can write to that file?" -- no, because it is not a file on the device. It is a file on your development machine. Assets are not files on the device, and they are read-only. You are welcome to write a copy to [internal storage](https://commonsware.com/blog/2019/10/06/storage-situation-internal-storage.html), for example. – CommonsWare Jul 26 '20 at 19:26

1 Answers1

0
try {
        BufferedReader bufferReader = new BufferedReader(new FileReader(file);
        try {
            String line = bufferReader.readLine();
            while(line != null) { 
            //do something
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
         e.printStackTrace();
    }
Zeh Renics
  • 23
  • 4