yu华南理工大学网络学院2014秋季
“计算机操作系统”课程设计大作业
一、题目: 用文件实现的学生成绩管理系统
二、目的
学生通过本次实验编程实现一个班级学生成绩的管理,使学生了解文件的主要操作(创建、读、写、增加和删除记录等)。
三、内容和要求
1、编写一个学生成绩管理的软件系统,语言不限。
2、软件中能够随时增加学生成绩记录(姓名、班级、学号、课程名称、成绩),这些记录存放到磁盘文件中。
3、利用磁盘文件的系统接口函数编程实现对学生成绩进行管理:以各种方式查询成绩、修改成绩;显示所有的学生成绩。
4、编写将一个班级的成绩复制到另一个文件的功能。
5、学习使用文件编程,实现指定班级成绩文件的删除操作。
6、能够对学生成绩记录进行文件备份和还原。
7、本实验的目的是练习文件操作,因此该软件不能使用数据库存放信息,只能用普通文件存放信息。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-11-24 15:27 StudentCourse
目录 0 2014-11-24 15:26 StudentCourseexe
目录 0 2014-11-22 09:46 StudentCourseexeackup
目录 0 2014-11-22 09:52 StudentCourseexedata
文件 12002 2014-11-25 09:33 StudentCourseexeFileUtil.class
目录 0 2014-11-22 09:46 StudentCourseexejre
目录 0 2014-11-22 09:46 StudentCourseexejrein
文件 10240 2011-09-17 10:28 StudentCourseexejreinattach.dll
文件 1208320 2011-09-17 10:28 StudentCourseexejreinawt.dll
文件 114688 2011-09-17 10:28 StudentCourseexejreinaxbridge.dll
目录 0 2014-11-22 09:46 StudentCourseexejreinclient
文件 2641920 2011-09-17 10:28 StudentCourseexejreinclientjvm.dll
文件 1447 2011-09-17 10:28 StudentCourseexejreinclientXusage.txt
文件 192512 2011-09-17 10:28 StudentCourseexejreincmm.dll
文件 143360 2011-09-17 10:28 StudentCourseexejreindcpr.dll
文件 77824 2011-09-17 10:28 StudentCourseexejreindeploy.dll
文件 405504 2011-09-17 10:28 StudentCourseexejreindeployJava1.dll
文件 16896 2011-09-17 10:28 StudentCourseexejreindt_shmem.dll
文件 13312 2011-09-17 10:28 StudentCourseexejreindt_socket.dll
文件 69632 2011-09-17 10:28 StudentCourseexejreineula.dll
文件 339968 2011-09-17 10:28 StudentCourseexejreinfontmanager.dll
文件 15872 2011-09-17 10:28 StudentCourseexejreinhpi.dll
文件 139264 2011-09-17 10:28 StudentCourseexejreinhprof.dll
文件 98304 2011-09-17 10:28 StudentCourseexejreininstrument.dll
文件 12800 2011-09-17 10:28 StudentCourseexejreinioser12.dll
文件 7680 2011-09-17 10:28 StudentCourseexejreinj2pcsc.dll
文件 41984 2011-09-17 10:28 StudentCourseexejreinj2pkcs11.dll
文件 10240 2011-09-17 10:28 StudentCourseexejreinjaas_nt.dll
文件 126976 2011-09-17 10:28 StudentCourseexejreinjava.dll
文件 139264 2011-09-17 10:28 StudentCourseexejreinjava.exe
文件 73728 2011-09-17 10:28 StudentCourseexejreinjavacpl.cpl
............此处省略78个文件信息
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* 操作文件 实现对文件的创建、读、写、删除等操作
* 学生成绩的添加、查找、修改 是将文件内容读取到内存list中,进行操作,完成后,将内容写回到文件中
* @author Administrator
*
*/
public class FileUtil {
private static final String mainFileName = “main.db“;
/**
* 添加学生成绩 保存到文件
* @param content
* @return
*/
public static boolean saveFileContent(String content){
FileWriter writer = null;
try {
String path = System.getProperty(“user.dir“);//获取当前路径
String fileName = path+“/“+mainFileName;//学生成绩文件(主文件)
File file = new File(fileName);
if(!file.exists())//判断该文件是否存在
file.createNewFile();//不存在新建一个空文件
writer = new FileWriter(fileName true);
writer.write(content+“
“);//学生成绩写入文件
} catch (IOException e) {
e.printStackTrace();
return false;
}finally{
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return true;
}
/**
* 根据班级查询
* @param className
* @return
*/
public static List queryByClassName(String className){
BufferedReader reader = null;
List list = new ArrayList();
try{
String path = System.getProperty(“user.dir“);
String fileName = path+“/“+mainFileName;
File file = new File(fileName);
reader = new BufferedReader(new FileReader(file));
String tempString = null;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
if(!““.equals(tempString)){
Student student = StringToStudent(tempString); //将学生成绩字符串转换成学生对象
if(className.equals(student.getClassName())) //如果班级与输入的班级一致,就将学生信息添加到list中
list.add(student);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
return list;
}
/**
* 根据课程查询
* @param courseName
* @return
*/
public static List queryByCourseName(String courseName){
BufferedReader reader = null;
List list = new ArrayList();
try{
String path = System.getProperty(“user.dir“);
String fileName = path+“/“+mainFileName;
File file = new File(fileName);
reader = new BufferedReader(new FileReader(file));
String tempString = null;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
if(!““.equals(tempString)){
Student student = StringToStudent(tempString); //将学生成绩字符串转换成学生对象
if(courseName.equals(student.getCourseName()))//如果课程与输入的课程一致,就将学生信息添加到list中
list.add(student);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-11-24 15:27 StudentCourse
目录 0 2014-11-24 15:26 StudentCourseexe
目录 0 2014-11-22 09:46 StudentCourseexeackup
目录 0 2014-11-22 09:52 StudentCourseexedata
文件 12002 2014-11-25 09:33 StudentCourseexeFileUtil.class
目录 0 2014-11-22 09:46 StudentCourseexejre
目录 0 2014-11-22 09:46 StudentCourseexejrein
文件 10240 2011-09-17 10:28 StudentCourseexejreinattach.dll
文件 1208320 2011-09-17 10:28 StudentCourseexejreinawt.dll
文件 114688 2011-09-17 10:28 StudentCourseexejreinaxbridge.dll
目录 0 2014-11-22 09:46 StudentCourseexejreinclient
文件 2641920 2011-09-17 10:28 StudentCourseexejreinclientjvm.dll
文件 1447 2011-09-17 10:28 StudentCourseexejreinclientXusage.txt
文件 192512 2011-09-17 10:28 StudentCourseexejreincmm.dll
文件 143360 2011-09-17 10:28 StudentCourseexejreindcpr.dll
文件 77824 2011-09-17 10:28 StudentCourseexejreindeploy.dll
文件 405504 2011-09-17 10:28 StudentCourseexejreindeployJava1.dll
文件 16896 2011-09-17 10:28 StudentCourseexejreindt_shmem.dll
文件 13312 2011-09-17 10:28 StudentCourseexejreindt_socket.dll
文件 69632 2011-09-17 10:28 StudentCourseexejreineula.dll
文件 339968 2011-09-17 10:28 StudentCourseexejreinfontmanager.dll
文件 15872 2011-09-17 10:28 StudentCourseexejreinhpi.dll
文件 139264 2011-09-17 10:28 StudentCourseexejreinhprof.dll
文件 98304 2011-09-17 10:28 StudentCourseexejreininstrument.dll
文件 12800 2011-09-17 10:28 StudentCourseexejreinioser12.dll
文件 7680 2011-09-17 10:28 StudentCourseexejreinj2pcsc.dll
文件 41984 2011-09-17 10:28 StudentCourseexejreinj2pkcs11.dll
文件 10240 2011-09-17 10:28 StudentCourseexejreinjaas_nt.dll
文件 126976 2011-09-17 10:28 StudentCourseexejreinjava.dll
文件 139264 2011-09-17 10:28 StudentCourseexejreinjava.exe
文件 73728 2011-09-17 10:28 StudentCourseexejreinjavacpl.cpl
............此处省略78个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)