2021-07-30

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);
					//System.out.println("提交"+context);
					break;
				}		
			}
			br.close();
		}
		//将全部人员名单添加至list2中
		while((s=b2.readLine())!=null){
            list2.add(s);
        }
		//移除名单中已经提交的人
		list2.removeAll(list1);
		
		for(String s1:list2) {
			System.out.println("未提交"+s1);
		}
		b2.close();
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值