vendredi 15 juillet 2016

Error java IO total size of folder

my program counts and prints out the number of files of folder and the total size in bytes of all files but i have error ("Exception in thread "main" java.lang.NullPointerException")

import java.io.*;

public class Ex5 { public static void a(String s) throws IOException{

    long size=0;
    File f=new File(s);
    File [] a=f.listFiles();
    System.out.println("the number of files in this folder :"+a.length);
    for(int i=0;i<a.length;i++){
    if(a[i].isFile()){
        size=size+a[i].length();

    }else
        a(a[i].getName());

    }
System.out.println("the folder size is :"+size);
}
public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
  a("C:\Users\hackour\Documents\javablue\applet");
}

}

Aucun commentaire:

Enregistrer un commentaire