Read/write file to internal private storage

前端 未结 4 1201
太阳男子
太阳男子 2020-12-14 12:14

I\'m porting the application from Symbian/iPhone to Android, part of which is saving some data into file. I used the FileOutputStream to save the file into

4条回答
  •  -上瘾入骨i
    2020-12-14 12:52

    This isn't really Android-specific but more Java oriented.

    If you prefer line-oriented reading instead, you could wrap the FileInputStream in an InputStreamReader which you can then pass to a BufferedReader. The BufferedReader instance has a readLine() method you can use to read line by line.

    InputStreamReader in = new InputStreamReader(fis);
    BufferedReader br = new BufferedReader(in);
    String data = br.readLine()
    

    Alternatively, if you use the Google Guava library you can use the convenience function in ByteStreams:

    String data = new String(ByteStreams.toByteArray(fis));
    

提交回复
热议问题