操作系统课程设计报告二级文件系统java.doc

上传人:jian****018 文档编号:8898903 上传时间:2020-04-01 格式:DOC 页数:13 大小:104KB
返回 下载 相关 举报
操作系统课程设计报告二级文件系统java.doc_第1页
第1页 / 共13页
操作系统课程设计报告二级文件系统java.doc_第2页
第2页 / 共13页
操作系统课程设计报告二级文件系统java.doc_第3页
第3页 / 共13页
点击查看更多>>
资源描述
操作系统课程设计报告题目: 为Linux系统设计一个简单的二级文件系统 指导老师:翟一鸣 时间:2012.8.30一 课程设计的目的课程设计目的使学生熟悉文件管理系统的设计方法;加深对所学各种文件操作的了解及其操作方法的特点。通过模拟文件系统的实现,深入理解操作系统中文件系统的理论知识, 加深对教材中的重要算法的理解。同时通过编程实现这些算法,更好地掌握操作系统的原理及实现方法,提高综合运用各专业课知识的能力。二 课程设计的要求 1.可以实现下列几条命令:login 用户登录dir 列目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件2列目录时要列出文件名,物理地址,保护码和文件长度3源文件可以进行读写保护三 算法设计本次二级文件系统主要分为五大模块,分别是用户登录模块、新建目录模块、新建文件模块、删除文件模块和读取文件模块。用户登录成功后才可以进行其他模块的操作。1 用户登录模块 用户登录模块要求用户输入用户,当输入正确后才能进行其他模块操作,否则提示用户名不存在并询问用户是否用此名进行注册。若用户名未满,则提示注册成功,否则提示用现有注册用户,进行登录,并返回到登录界面。用户登录模块流程图如图1所示。开始 输入login命令 否输入用户名是否注册用户是否存在 是 否 是进行其他模块图1 用户登录模块流程图2新建文件模块新建文件模块是在用户出入create指令后进行的,进入后会要求用户输入文件名,并判断文件名是否存在,若没有则在要求用户输入文件读写权限,否则重新输入新的文件名。新建文件模块流程图如图2所示。开始 输入create命令 输入文件名文件名是否存在 是 否输入权限图2 新建文件流程图3 删除文件模块开始删除文件模块是根据用户鼠标右击时选择到的节点来确定要删除节点的名字与路径,然后判断该节点是目录还是文件。若是文件则直接删除文件,若是目录则进入该目录再删除其全部文件。删除文件模块流程图如图4所示。 输如open 文件名 提示无此文件文件名是否存在 否 输入权限 是图4 删除文件模块流程图4读取文件模块开始读取文件模块,要求用户要在文件打开的前提下,将磁盘中的内容读取到内存中。读取文件流程图如图5所示。 Open 文件 输如read 文件名 文件是否存在 是 提示文件未打开文件是否已打开 否显示文件内容图5 读取文件模块流程图5 写入文件模块 写入文件模块,思路与读取文件模块将本相同,只是添加了对读写权限的判断。6 遍历文件遍历文件,根据在用户登陆时,记录的值,在二维数组中,找到用户的所有文件对象,将相应的必须属性全部打印出来。四 程序源代码1. 文件对象相关代码 package com.file;import java.io.Serializable;public class FilePro implements SerializableString filename;String content;String username;int flag;int protect;public FilePro(String filename,String username,String content,int flag,int protect)this.filename = filename;this.username = username;this.content = content;this.flag = flag;this.protect = protect;2. 文件读写操作 package com.file;import java.io.*;import java.util.*;public class FileCon Object data = new Object7100;ObjectInputStream in = null;ObjectOutputStream out = null;String path = D:file;public FileCon()for(int i = 0;i7;i+)for(int j = 0;j100;j+)dataij = new FilePro(,null,1,0);public Object readData()try in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(path);data = (Object) in.readObject(); catch(EOFException e) catch (Exception e) return data;public void writeData(Object data)try out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(path);out.writeObject(data);out.flush(); catch (Exception e) e.printStackTrace(); 3.用户名操作public class UserCon List list = new ArrayList();ObjectInputStream in = null;ObjectOutputStream out = null;String path = D:user;public List readUser()try in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(path);list = (List) in.readObject(); catch(EOFException e) catch (Exception e) return list;public void writeUser(List list)try out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(path);out.writeObject(list);out.flush(); catch (Exception e) e.printStackTrace(); 4.主程序package com.file;import java.util.*;public class FileSystem Object data = new Object7100;FileCon fc = new FileCon();List user = new ArrayList();UserCon uc = new UserCon();String cmd = new String2;int currentuser = 0;public FileSystem() data = fc.readData();user = uc.readUser();public static void main(String args) FileSystem fs = new FileSystem();fs.help();public void help() System.out.println(欢迎使用该文件系统);System.out.print(create );System.out.println(创建文件);System.out.print(dir );System.out.println(列目录文件);System.out.println(exit 退出系统);System.out.println(以下命令需加文件名);System.out.println(eg:open *);System.out.print(open );System.out.println(打开文件);System.out.print(close );System.out.println(关闭文件);System.out.print(read );System.out.println(读文件);System.out.print(write );System.out.println(写文件);System.out.print(delete );System.out.println(删除文件);command();public void command() System.out.print(root:);String comd = null;Scanner input = input = new Scanner(System.in);comd = input.nextLine();String cmd = new String2;cmd = comd.split( );if (cmd0.equals(login)login();else if (cmd0.equals(create)create();else if (cmd0.equals(dir)dir();else if (cmd0.equals(delete)delete(cmd1);else if (cmd0.equals(open)open(cmd1);else if (cmd0.equals(close)close(cmd1);else if (cmd0.equals(read)read(cmd1);else if (cmd0.equals(write)write(cmd1);else if (cmd0.equals(exit)System.out.println(退出系统!); System.exit(0);else System.out.println(指令错误!);command();public void login() boolean f = false;System.out.println(请输入用户名:);Scanner input = input = new Scanner(System.in);String username = input.next();for (int i = 0; i user.size(); i+) if (user.get(i).equals(username) System.out.println(登陆成功!);currentuser = i;f = true;break;if (!f) System.out.println(该用户不存在,是否以此用户名注册?y注册,其他返回);String cho = input.next();if (cho.equals(y) if (user.size() = 7)System.out.println(对不起用户已满,请利用其他已注册账户登录);else user.add(username);uc.writeUser(user);System.out.println(注册成功!请重新登录);login();command();/ 目录public void dir() System.out.println(文件名t + 用户名t + 物理地址t + 保护码t + 文件长度);for (int i = 0; i 100; i+) FilePro fp1 = (FilePro) datacurrentuseri;if (!fp1.filename.equals()System.out.println(fp1.filename + t + fp1.username + t+ currentuser + i + t + fp1.protect + t+ fp1.content.length();command();/ 创建文件public void create() Scanner input = input = new Scanner(System.in);boolean f = true;boolean fl = false;String filename = null;dofl = false; System.out.print(请输入文加名:); filename = input.next();for (int i = 0; i 100; i+) FilePro fp1 = (FilePro) datacurrentuseri;if (fp1.filename.equals(filename) System.out.println(文件已存在!);fl = true;break;while(fl);System.out.print(请输入权限:);int protect = input.nextInt();FilePro fp = new FilePro(filename, user.get(currentuser), , 1,protect);for (int i = 0; i 100; i+) FilePro fp1 = (FilePro) datacurrentuseri;if (fp1.filename.equals() datacurrentuseri = fp;fc.writeData(data);System.out.println(创建成功!);f = false;break;if (f) System.out.println(磁盘已满);command();/ 删除文件public void delete(String file) boolean f = true;for (int i = 0; i 100; i+) FilePro fp1 = (FilePro) datacurrentuseri;if (fp1.filename.equals(file) fp1.filename = ;fp1.content = null;fp1.flag = 1;fp1.username = null;fc.writeData(data);System.out.println(删除成功!);f = false;break;if (f) System.out.println(无此文件);command();/ 打开文件public void open(String file) boolean f = true;for (int i = 0; i 100; i+) FilePro fp1 = (FilePro) datacurrentuseri;if (fp1.filename.equals(file) if (fp1.flag = 0)System.out.println(文件已打开!);else fp1.flag = 0;System.out.println(文件打开成功!);f = false;break;if (f) System.out.println(无此文件);command();/ 关闭文件public void close(String file) boolean f = true;for (int i = 0; i 100; i+) FilePro fp1 = (FilePro) datacurrentuseri;if (fp1.filename.equals(file) if (fp1.flag = 1)System.out.println(文件未打开!);else fp1.flag = 1;System.out.println(文件关闭成功!);f = false;break;if (f) System.out.println(无此文件);command();/ 读文件public void read(String file) boolean f = true;for (int i = 0; i 100; i+) FilePro fp1 = (FilePro) datacurrentuseri;if (fp1.filename.equals(file) if (fp1.flag = 1)System.out.println(文件未打开!请先将文件打开!);else System.out.println(fp1.content);f = false;break;if (f) System.out.println(无此文件);command();/ 写文件public void write(String file) Scanner input = input = new Scanner(System.in);boolean f = true;for (int i = 0; i 100; i+) FilePro fp1 = (FilePro) datacurrentuseri;if (fp1.filename.equals(file) if (fp1.flag = 1)System.out.println(文件未打开!请先将文件打开!);else if (fp1.protect != 0)System.out.println(对不起,您没有写入的权限!);else System.out.println(请输入要写入的内容:);String ss = input.next();fp1.content = fp1.content + ss;fc.writeData(data);System.out.println(写入成功);f = false;break;if (f) System.out.println(无此文件);command();五 程序运行截图六 心得体会 对于本次操作系统课程设,由于对二级文件的内容比较陌生,刚起步阶段花了很大时间去思考,但是仍然还是比较模糊。当完成设计时,感觉还是不是太了解,总感觉得到的和要求的有些差别,不过对二级文件系统也有了进一步的了解,并且还对操作系统应用有了更深入的认识。总体来说,这次课程下来,发现自己的,语言基础掌握的一点也不好,让我遇到了许多的问题。
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 大学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!