我正在尝试从一个位置获取所有文本文件,然后检查每个文件名(ACMEMM_ADDITIONAL_ATTRIBUTE_02172015_075611),然后将其修剪为02172015_075611。执行此操作后,我将每个文件名插入字符串数组,但是当我这样做时我我在mr [i] = s时得到Null指针异常; 请帮忙。
import java.io.File;
public class dog{
public void listFiles(){
File directory = new File("C://Users//422405//Desktop//Az_Support_Process//New folder (3)");
//get all the files from a directory
File[] fList = directory.listFiles();
System.out.println(fList.length);
int count=0;
int i=0;
String s;
String [] mr=null;
for (File file : fList){
if (file .isFile()){
count++;
s=file.getName().replaceAll("[^0-9]", "");;
System.out.println(s);
mr[i]=s;
i++;
//System.out.println(i);
}}
//System.out.println(mr.length);
if(count==20){
}
System.out.println(count);
}
public static void main(String[] args)
{
System.out.println("Hello");
dog d=new dog();
d.listFiles();
}
}