当我在 /home/meow 目录中搜索某些内容并列出所有文件时,该程序运行良好,但是当我尝试列出系统“/”上的所有文件时,它在打印 /bin 目录的内容后崩溃。我也尝试将其作为 SUDO java pin 执行
import java.io.*;
public class Pin
{
public static void printFiles(String a)
{
File dir = new File(a);
for(File file:dir.listFiles())
{
if(file.isFile())
{
System.out.println(file);
}
else
{
printFiles(file.toString());
}
}
}
public static void main(String[] args)
{
printFiles("/");
}
}
这是我的输出...
vikkyhacks java # sudo java Pin
/lib64/ld-linux-x86-64.so.2
/bin/ntfsmove
/bin/init-checkconf
/bin/chown
/bin/mt-gnu
/bin/ntfs-3g.usermap
/bin/mountpoint
/bin/plymouth
/bin/s
/bin/bunzip2
/bin/gzexe
/bin/fgconsole
/bin/ntfstruncate
/bin/i
/bin/plymouth-upstart-bridge
/bin/fgrep
/bin/ping
/bin/lesspipe
/bin/rbash
/bin/gzip
/bin/ntfsmftalloc
/bin/lowntfs-3g
/bin/tailf
/bin/bzcat
/bin/tempfile
/bin/domainname
/bin/touch
/bin/zcmp
/bin/mktemp
/bin/nano
/bin/unicode_start
/bin/ln
Exception in thread "main" java.lang.NullPointerException
at Pin.printFiles(Pin.java:9)
at Pin.printFiles(Pin.java:17)
at Pin.printFiles(Pin.java:17)
at Pin.main(Pin.java:23)