資源簡介
用Java語言設計一個學生信息管理系統,對學生信息進行增刪改查。
該系統有簡單的界面,GUI,學生信息存儲在文件中,若原來沒有文件,會自動創建。
可查看https://blog.csdn.net/H200102/article/details/94744641

代碼片段和文件信息
package?Student_Manage;
import?java.io.*;
import?java.util.*;
//修改,刪除,增加某個學生信息
class?Function?{
//本程序學生數量不多,用數組列表ArrayList??當學生數據多的時候,考慮用鏈表
????ArrayList?arry=new?ArrayList();??
public?Function()???????????//讀文件,將文件中的學生信息存放在數組列表
{
this.readfile();
}
//根據學號查找學生信息,找到返回學號,找不到返回-1
public?int?find(String?str)?
{
????for?(int?i?=?0;?i ??????if?(arry.get(i).getStuID().equals(str))
return?i;//等于在數組列表的位置
return?-1;
}
//修改學生信息
public?void?update(student_information?stu)?{
int?flag=find(stu.getStuID());????//查找是否存在
arry.set(flag?stu); ???//替換?flag?處的學生信息
}
//?讀文件,
public?boolean?readfile()?{ ?
String?t=null;
try{
FileReader?f1?=?new?FileReader(“student.txt“);
BufferedReader?br=new?BufferedReader(f1);
arry.clear();????// 清除原數組列表中的數據
while?((t=?br.readLine())!=?null)
{
??String?[]?s=t.split(“\\s+“); ?
??student_information?st=new?student_information(s[0]s[1]s[2]s[3]s[4]s[5]s[6]);//注意若該文件每行沒有七個字符串,則會出錯
??arry.add(st);
??System.out.println(“讀取文件:“);
??System.out.println(s[0]);
}
?????f1.close();
?????br.close(); ?????
?????return?true;
}?catch?(IOException?e)?{
//?TODO?自動生成的?catch?塊
e.printStackTrace();
return?false;
}
?????}
//添加學生信息
public?boolean?add(student_information?stu)
?????{
System.out.println();
System.out.println(“要添加的學生“);
System.out.println(stu.fileString());
System.out.println();
if?(find(stu.getStuID())!=-1)
return?false;
arry.add(stu);?
return?true;
}
//寫注意每行必須有七個元素,否則讀取文件并判斷是否存在時會出錯時會出錯,沒有輸入的用---代替
public?boolean?writefile()?{
FileWriter?fw=null;
BufferedWriter?out=null;
try?{
?fw?=?new?FileWriter(“student.txt“);????
?out?=?new?BufferedWriter(fw);
?//姓名學號等中間隔一個空格
for(int?i=0;i String?s=arry.get(i).fileString();
System.out.println(“數組列表數據:“);
System.out.println(arry.get(i).fileString());
???? out.write(s);
???? out.newLine();
????}
out.close();
fw.close();
return?true;
}?catch?(IOException?e)?{
e.printStackTrace();
return?false;
}
???}
//刪除學生信息并且文件中的內容也要修改
public?boolean?delete(String?s) //添加學生記信息
{??
int?pos=find(s);
if?(pos==-1)
return?false;
arry.remove(pos);????
return?true;
}
/*
//刪除學生信息,并且重寫文件內容
?public?boolean?delete(String?s)?{
????????File?file?=new?File(“student.txt“);
????????try?{
????????????if(!file.exists())?{
????????????????file.createNewFile();
????????????}
????????????FileWriter?fileWriter?=new?FileWriter(file);
????????????fileWriter.write(““);
????????????fileWriter.flush();
????????????fileWriter.close(); ????????????
???? int?flag=find(s); ????
???? System.ou
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-07-05?10:30??Student_Manage\
?????文件?????????301??2019-06-02?16:24??Student_Manage\.classpath
?????文件?????????390??2019-06-15?10:44??Student_Manage\.project
?????目錄???????????0??2019-06-15?10:44??Student_Manage\.settings\
?????文件?????????598??2019-06-02?16:24??Student_Manage\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2019-06-20?11:37??Student_Manage\bin\
?????目錄???????????0??2019-06-20?11:37??Student_Manage\bin\Student_Manage\
?????文件????????3303??2019-07-05?16:59??Student_Manage\bin\Student_Manage\Function.class
?????文件????????2112??2019-06-20?11:37??Student_Manage\bin\Student_Manage\Input.class
?????文件?????????793??2019-06-20?11:37??Student_Manage\bin\Student_Manage\Login$1.class
?????文件?????????793??2019-06-20?11:37??Student_Manage\bin\Student_Manage\Login$2.class
?????文件????????1834??2019-06-20?11:37??Student_Manage\bin\Student_Manage\Login.class
?????文件?????????426??2019-06-20?11:37??Student_Manage\bin\Student_Manage\Main.class
?????文件????????2950??2019-07-05?18:34??Student_Manage\bin\Student_Manage\ManagerLogin$1.class
?????文件?????????724??2019-07-05?18:34??Student_Manage\bin\Student_Manage\ManagerLogin$2.class
?????文件????????2842??2019-07-05?18:34??Student_Manage\bin\Student_Manage\ManagerLogin$3.class
?????文件????????1760??2019-07-05?18:34??Student_Manage\bin\Student_Manage\ManagerLogin$4.class
?????文件????????2904??2019-07-05?18:34??Student_Manage\bin\Student_Manage\ManagerLogin$5.class
?????文件?????????760??2019-07-05?18:34??Student_Manage\bin\Student_Manage\ManagerLogin$6.class
?????文件????????4780??2019-07-05?18:34??Student_Manage\bin\Student_Manage\ManagerLogin.class
?????文件?????????724??2019-07-05?20:12??Student_Manage\bin\Student_Manage\StudentLogin$1.class
?????文件????????2842??2019-07-05?20:12??Student_Manage\bin\Student_Manage\StudentLogin$2.class
?????文件?????????760??2019-07-05?20:12??Student_Manage\bin\Student_Manage\StudentLogin$3.class
?????文件????????4275??2019-07-05?20:12??Student_Manage\bin\Student_Manage\StudentLogin.class
?????文件????????4764??2019-06-20?11:37??Student_Manage\bin\Student_Manage\show_stuall.class
?????文件????????6955??2019-06-20?11:37??Student_Manage\bin\Student_Manage\showones.class
?????文件????????2428??2019-06-20?11:37??Student_Manage\bin\Student_Manage\student_information.class
?????目錄???????????0??2019-06-15?10:45??Student_Manage\src\
?????目錄???????????0??2019-06-16?14:19??Student_Manage\src\Student_Manage\
?????文件????????3537??2019-07-05?16:59??Student_Manage\src\Student_Manage\Function.java
?????文件????????1366??2019-06-20?11:37??Student_Manage\src\Student_Manage\Input.java
............此處省略9個文件信息
評論
共有 條評論