Ruang penulis
← Kembali ke jurnal
Core API

How do I check if a directory is not empty?

package org.kodejava.io; import java.io.File; public class EmptyDirCheck { public static void main(String[] args) { File file = new File("D:/Downloads"); // Check to see if the object represent a directory. if (file.isDirectory()) { // Get list of file in the directory. When its length is not zero // the folder is not empty. String[] files = […]

DWayan · 08 Agt 2008 · 1 menit baca

Artikel oleh Wayan · Sumber: Kode Java ↗

Terjemahan artikel ini belum tersedia. Isi asli ditampilkan.

package org.kodejava.io;

import java.io.File;

public class EmptyDirCheck {
    public static void main(String[] args) {
        File file = new File("D:/Downloads");

        // Check to see if the object represent a directory.
        if (file.isDirectory()) {
            // Get list of file in the directory. When its length is not zero
            // the folder is not empty.
            String[] files = file.list();

            if (files != null && files.length > 0) {
                System.out.println(file.getPath() + " is not empty!");
            }
        }
    }
}
← Jelajahi catatan lainnya