• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Java实现学生信息管理系统IO版本

java 搞代码 4年前 (2022-01-05) 26次浏览 已收录 0个评论

这篇文章主要为大家详细介绍了Java实现学生信息管理系统IO版本,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

学生信息管理系统IO版本代码实现(java),供大家参考,具体内容如下

之前写过的一个学生信息管理系统是用集合类来写的,但是不能实现代码在文档中的存储功能,每次运行过后都得重新输入数据,无法做到保存的功能。

而用IO流进行学生信息管理系统的编写以后将数据存储在文本文件中,以后每次访问都可以访问到之前已经存到的数据,类似于数据库的一个存储功能(这里并没有用到Mysql数据库,仅仅是用文本文档来进行数据的一系列存储)

以下是代码的实现过程:

主类

 package zjh; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class StudentManageTest { public static void main(String[] args) throws IOException { String FileName = "students.txt"; while(true) { System.out.println("----欢迎来到学生信息管理系统----"); System.out.println("请输入你想要进行的操作"); System.out.println("1:查看所有学生信息"); System.out.println("2:添加学生信息"); System.out.println("3:删除学生信息"); System.out.println("4:修改学生信息"); System.out.println("5:退出"); Scanner scanner = new Scanner(System.in); String choice = scanner.nextLine(); switch (choice) { case "1": findAllStudents(FileName); break; case "2": addStudent(FileName); break; case "3": deleteStudent(FileName); break; case "4": updateStudent(FileName); break; case "5": default: System.out.println("正在退出系统,欢迎下次继续使用"); System.exit(0);//JVM退出 break; } } } //从文件中读数据到集合 public static void readData(String fileName,ArrayList array) throws IOException { //创建输入缓冲流对象 BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; while((line=br.readLine())!=null) { String[] datas = line.split(","); Student s = new Student(); s.setId(datas[0]); s.setName(datas[1]); s.setAge(datas[2]); s.setAddress(datas[3]); array.add(s); } br.close(); } //把集合中的数据写入文件 public static void writeData(String fileName,ArrayList array) throws IOException { //创建输出缓冲流对象 BufferedWriter bw = new BufferedWriter(new FileWriter(fileName)); for(int x=0; x array = new ArrayList(); //从文件中把数据读取到集合中 readData(FileName, array); Scanner scanner = new Scanner(System.in); while(true) { System.out.println("请输入你要修改的学号:"); String id = scanner.nextLine(); int index = -1; for(int x=0; x array = new ArrayList(); //从文件中把数据读取到集合中 readData(FileName, array); Scanner scanner = new Scanner(System.in); while(true) { System.out.println("请输入你要删除的学号"); String id = scanner.nextLine(); int index = -1; for(int x=0; x array = new ArrayList(); //从文件中把数据读取到集合中 readData(FileName, array); Scanner scanner = new Scanner(System.in); String id; while(true) { System.out.println("请输入你要添加的学号:"); int flag =0; id = scanner.nextLine(); for(int x=0; x array = new ArrayList(); //从文件中把数据读取到集合中 readData(FileName, array); if(array.size()==0) { System.out.println("当前没有任何学生信息,请添加后再使用"); } System.out.println("学号\t姓名\t年龄\t居住地"); for(int x=0; x</div><p>Student类</p><div class="gaodaimacode"><pre class="prettyprint linenums"> package zjh; public class Student { private String id; private String name; private String age; private String address; public Student() { } public Student(String id, String name, String age, String address) { this.id = id; this.name = name; this.age = age; this.address = addr<p style="color:transparent">来源gao!%daima.com搞$代*!码网</p>ess; } 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; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } }

以上就是Java实现学生信息管理系统IO版本的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Java实现学生信息管理系统IO版本
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址