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

后端 未结 12 1217
南笙
南笙 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:28

    The idea of your first snippet is right. You probably meant to check iByteCount == -1: whether the file has at least one byte:

    if (iByteCount == -1)  
        System.out.println("NO ERRORS!");
    else
        System.out.println("SOME ERRORS!");
    

提交回复
热议问题