0
我的程序計算並打印文件夾的文件數量和總大小以字節爲單位的所有文件,但我有錯誤(「線程中的異常」main「java.lang.NullPointerException」)錯誤java IO文件夾的總大小
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");
}
}
第一個節目是印刷精美的文件夾的小程序的總規模,但是當我在文件夾中創造新的文件夾小程序中的程序使這個錯誤 我把如果(一!= null) 但該程序不打印子文件夾大小的文件夾的總大小 thx幫助 注意:(「第一個applet文件夾只有文件」) – hackour
問題出在一個(a [i ] .getName()); 它應該是大小+ = a(a [i] .getname()); – hackour