自动核对文件提交信息程序使用教程(学生版)
功能简介
本程序实现的功能:
- 通过比对学生名单和自动生成的文件提交名单,生成未提交人员列表
- 生成文件列表里不在学生名单中文件信息
- 生成重复提交的文件信息
使用教程
关于使用环境
由于本程序开发未考虑过多,使用 java 语言开发,生成文件不能再没有 java 环境状况下运行,如有需求可联系作者,邮箱见文末。
文件目录介绍
- 第一个文件夹 data 是用来存放待检测文件的;也就是别人提交给你的文件,你需要核对的目标文件。
- 第二个文件 Main.jar 是主程序文件,当你准备就绪的时候,双击此文件即可生成out.txt 和 SubmitList.txt 。
- 第三个文件 out.txt 这个文件是结果文件,是由程序自动生成的,使用前不存在此文件,即使存在也不会对结果造成影响。
- 第四个文件 studentlList.txt 这个文件是非常重要的文件,里面的数据是格式化数据,在源代码中是采用 空格 和 回车 切分字符串。所以,系统中规定的格式是 学号 姓名 ,例如 20203177xxxx kirk 然后回车第二行。这边建议,直接将 Excel 中的表格复制到此文本文件(学号在前姓名在后)。
- 第五个文件 SubmitList.txt 是系统检测到的文件信息并提取学号后的列表,由系统自动生成。
操作流程
建议,首先导入学生名单,也就是在 studentList.txt 文件中粘贴学生名单,这个文件也是可以手动创建的。(需要手动添加名单侧面说明了我是个弱鸡)。
然后,将待检测文件放到 data 内。
最后,双击 Main.jar 即可。如果,没产生新的文件信息,可以通过打开 cmd 进入到文件目录,输入指令 java -jar Mian.jar 后回车,可以看到运行异常报错信息,如果解决不了,请私我。
参考代码
有改进这个程序的 coders,请参考源码,定制自己的功能。
import java.io.*;
import java.text.*;
import java.util.*;
import java.lang.reflect.Array;
import java.nio.charset.StandardCharsets;
public class Main {
ArrayList<String> fullList = new ArrayList<>();
static ArrayList<String> ErrorInfo = new ArrayList<>();
static ArrayList<String> unknownStu = new ArrayList<>();
static ArrayList<String> ALlSubmitList = new ArrayList<>();
static ArrayList<student> stuList;
static String FilePath = "data";
static String studentListPath = "studentList.txt";
static String outPath = "out.txt";
static String fullListPath = "FullList.txt";
static String SubmitListPath = "SubmitList.txt";
static String jarPath;
public static void main(String[] args) {
// 初始化文件路径
// initPath();
// 读取学生名单
stuList = ReadFullList();
// 读取已提交作业名单
ArrayList<String> SubmitList = ReadList();
// System.out.println(ErrorInfo);
// 获取学生学号名单
ArrayList<String> IDList = new ArrayList<>();
for (student student : stuList) {
IDList.add(student.getID());
}
// 比较两个名单的差异
ArrayList<String> res = CompareList(SubmitList, IDList);
Arrays.sort(res.toArray());
// 输出未交名单
printList(res, stuList);
printAllSubmitList();
}
public static void printAllSubmitList(){
try {
BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(
SubmitListPath), StandardCharsets.UTF_8)
);
for(String string : ALlSubmitList){
bw.write("*** " + string + "\n");
// System.out.println(string);
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void printList(ArrayList<String> list, ArrayList<student> studentList) {
try {
BufferedWriter bw = null;
bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outPath), StandardCharsets.UTF_8));
// bw.write(jarPath + "\n");
bw.write("未提交作业名单:\n");
for (String string : list) {
// System.out.println(string);
int index = studentList.indexOf(new student(string, " "));
if (index == -1) {
System.out.println("未找到 " + string);
continue;
}
student stu = studentList.get(index);
// System.out.println(stu.toString());
bw.write(string + " - " + stu.getName() + "\n");
}
bw.write("\n\n检测到未知学生信息:\n");
for(String string : unknownStu){
bw.write(string + "\n");
}
bw.write("\n\n检测到异常信息:\n");
for(String string : ErrorInfo){
bw.write(string + "\n");
}
bw.close();
} catch (IOException e) {
System.out.print("Exception");
}
}
public static ArrayList<String> CompareList(ArrayList<String> list1,
ArrayList<String> list2) {
ArrayList<String> UnSubmitList = new ArrayList<>();
for (String string : list2) {
if (!list1.contains(string)) {
UnSubmitList.add(string);
// System.out.println(string);
}
// System.out.println("ok: " + string);
}
return UnSubmitList;
}
public static ArrayList<student> ReadFullList() {
ArrayList<student> StudentList = new ArrayList<>();
try {
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(
new FileInputStream(studentListPath), StandardCharsets.UTF_8));
while (true) {
String string = null;
try {
string = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (string == null)
break;
String[] stuInfo = string.split("\t");
if (stuInfo.length != 2) {
System.out.println("studentList error!");
unknownStu.add(string + " ———— 此学生信息可能有误!已跳过读取");
continue;
}
stuInfo[0] = stuInfo[0].trim();
stuInfo[1] = stuInfo[1].trim();
// System.out.println(Arrays.toString(stuInfo));
student stu = new student(stuInfo[0], stuInfo[1]);
StudentList.add(stu);
}
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return StudentList;
}
public static ArrayList<String> ReadList() {
File fpFullList = new File(FilePath);
File[] list = fpFullList.listFiles();
ArrayList<String> files = new ArrayList<>();
for (File file : list) {
files.add(file.getName());
}
files = getStuID(files);
return files;
}
public static ArrayList<String> getStuID(ArrayList<String> files) {
ArrayList<String> SubmitList = new ArrayList<>();
for (String string : files) {
int index = string.indexOf("20");
if(index == -1){
ErrorInfo.add("未知文件信息 --- 文件详情:" + string);
ALlSubmitList.add(string);
continue;
}
String res = string.substring(index, index + 12);
// System.out.println(res);
if (SubmitList.contains(res)) {
String errorInfo = "";
errorInfo +="重复文件:" + string;
ErrorInfo.add(errorInfo);
}
if(!stuList.contains(new student(res, ""))){
// System.out.println(res + "xxx");
unknownStu.add("未知学生信息 --- 文件详情:" + string);
}
SubmitList.add(res);
ALlSubmitList.add(res);
}
return SubmitList;
}
}
class student {
private String ID;
private String name;
public student(String ID, String name) {
this.ID = ID;
this.name = name;
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
student student = (student) o;
return Objects.equals(ID, student.ID);
}
@Override
public int hashCode() {
return Objects.hash(ID);
}
@Override
public String toString() {
return "student{" +
"ID='" + ID + '\'' +
", name='" + name + '\'' +
'}';
}
}
class getJarPath{
public File getCurrentJarDir() {
try {
String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
path = java.net.URLDecoder.decode(path, StandardCharsets.UTF_8);
File file = new File(path);
if (file.isFile()) {
return new File(file.getParent());
} else {
return file;
}
}catch (Exception e){
throw new RuntimeException(e);
}
}
}
怎么说呢,就是写来自己用的,代码写得超级丑,也没考虑工程上的规范,将就看看。如果有大佬愿意给蒟蒻的我改改,我当然会超级高兴的(顺便发我一份)。
End
联系方式:kirk的邮箱.
关于文件:
- 现成 Main.jar 文件百度云链接 提取码:kirk
- 蓝奏云链接 密码:1gmf
- 也可以私聊或者邮件我获得文件
注意一个问题(我遇到过的):idea 软件开发的时候,要用绝对路径,但是运行 jar 文件可以直接用相对路径
ok,你想给我点赞是不是,我看出来了。