Cómo listar todos los archivos de más de un argumento dado?

Bojan Petkovski:

Escribí este código y no puedo encontrar la manera de obtener el length()de un archivo. Quiero que todos los archivos que son mayores que 50 KB.

public static void main(String[] args) throws IOException {

    File f = new File(".");
    int KB = 1024;
    String[] files = f.list();

    for (String string : files) {
        if (f.length() > 50*KB)
        System.out.println(string);
    }
}
jeprubio:

El método length () para comprobar el tamaño del archivo es de archivo, no de cadena.

Prueba esto:

public static void main(String[] args) throws IOException {
    File f = new File(".");
    int KB = 1024;
    File[] allSubFiles = f.listFiles();
    for (File file : allSubFiles) {
        if (file.length() > 50 * KB) {
            System.out.println(file.getName());
        }
    }
}

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=345520&siteId=1
Recomendado
Clasificación