复制所有该文件下的文件,为什么会报错
private static void copyFile(File file,File file1) throws IOException {
File[] lf = file.listFiles();
for (File file2 : lf) {
if (file2.isFile()&&file2.toString().endsWith(".java")) {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file2.getAbsoluteFile()));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file1.getAbsoluteFile()+"\\"+file2.getName()));
byte[] arr = new byte[1024*9];
int bin;
while ((bin = bis.read(arr))!=-1) {
bos.write(arr,0,bin);
}
bis.close();
bos.close();
System.out.println("文件"+file2.getName()+"已复制");
}else if (file2.isDirectory()) {
copyFile(file2,file1);
}
}
}
Exception in thread "main" java.lang.NullPointerException
at com.wengjia.Demo2.copyFile(Demo2.java:19)
at com.wengjia.Demo2.copyFile(Demo2.java:38)
at com.wengjia.Demo2.main(Demo2.java:15)