java 有一个文本文件,里面是学生名单, 还有一个文件夹,里面是学生上交的作业, 编写程序,将所有的没有上交作 业的学生的名字打印出来
public class StampStudentList {
public static void main(String[] args) throws IOException {
Scanner scan=new Scanner(System.in);
System.out.println("请将要比对的文件夹的路径粘贴到此处");
String path=scan.nextLine();
String path1=path.replace("\\", "/");
File nameFile=new File(path1);
System.out.println("请将学生名单的文件路径粘贴在此处");
String pathStudent=scan.nextLine();
String path2=pathStudent.replace("\\", "/");
File nameFile1=new File(path2);
studentList(nameFile,nameFile1);
}
static void studentList(File file,File nameFile1) throws IOException {
String [] fileNameList=file.list();
BufferedReader b2 = new BufferedReader(new FileReader(nameFile1));
ArrayList<String> list2=new ArrayList<String>();
ArrayList<String> list1 =new ArrayList<String>();
String s=null;
String context=null;
for(String name:fileNameList) {
Reader rd=new FileReader(nameFile1);
BufferedReader br=new BufferedReader(rd);
while((context = br.readLine())!=null){
if(name.contains(context)) {
list1.add(context);
break;
}
}
br.close();
}
while((s=b2.readLine())!=null){
list2.add(s);
}
list2.removeAll(list1);
for(String s1:list2) {
System.out.println("未提交"+s1);
}
b2.close();
}
}