Reading and displaying data from a .txt file

后端 未结 10 961
北海茫月
北海茫月 2020-11-27 15:41

How do you read and display data from .txt files?

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 16:04

    In general:

    • Create a FileInputStream for the file.
    • Create an InputStreamReader wrapping the input stream, specifying the correct encoding
    • Optionally create a BufferedReader around the InputStreamReader, which makes it simpler to read a line at a time.
    • Read until there's no more data (e.g. readLine returns null)
    • Display data as you go or buffer it up for later.

    If you need more help than that, please be more specific in your question.

提交回复
热议问题