Android: Reading from file (Openfileinput)

前端 未结 2 1181
说谎
说谎 2020-12-05 19:09

I am trying to write a basic \"notepad\" app for a school project.

I have created the main class with an editText which I save as String te

相关标签:
2条回答
  • 2020-12-05 19:37

    An example of how to use openFileInput:

        FileInputStream in = openFileInput("filename.txt");
        InputStreamReader inputStreamReader = new InputStreamReader(in);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            sb.append(line);
        }
        inputStreamReader.close();
    
    0 讨论(0)
  • 2020-12-05 19:45

    The first parameter is the name of the file you are creating/updating when using openFileOutput method. Using the same parameter you have listed above it might look like:

    FileInputStream fis = openFileInput(textOutput);
    

    As for reading from a FileInputStream that is extremely well documented here and on the web. The best way to go about it also depends on the type of file you are reading (e.g. XML). So i will leave that for you to search on.

    Edit: Here is documentation

    0 讨论(0)
提交回复
热议问题