Most efficient way to check if a file is empty in Java on Windows

后端 未结 12 1199
南笙
南笙 2020-12-05 04:30

I am trying to check if a log file is empty (meaning no errors) or not, in Java, on Windows. I have tried using 2 methods so far.

Method 1 (Failure)

12条回答
  •  再見小時候
    2020-12-05 05:12

    Try FileReader, this reader is meant to read stream of character, while FileInputStream is meant to read raw data.

    From the Javadoc:

    FileReader is meant for reading streams of characters. For reading streams of raw bytes, consider using a FileInputStream.

    Since you wanna read a log file, FileReader is the class to use IMO.

提交回复
热议问题