Check if a File Is Empty in Java

1 min read
Date: 2023-07-04
This Java tutorial explores four methods for checking if a file is empty. The first two, using File.length()
and FileChannel.size()
, efficiently determine emptiness by checking file size (in bytes). The last two methods, employing BufferedReader.readLine()
and BufferedInputStream.available()
, read file contents to check for emptiness, offering less efficiency but handling cases where file existence isn't guaranteed. The best approach depends on application needs and whether file size or content inspection is preferred.
Read more: https://examples.javacodegeeks.com/checking-if-a-file-is-empty-in-java/
0
Subscribe to my newsletter
Read articles from Yatin B. directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
