版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、课程设计日期: 2010学年 秋学期 操作系统课程设计题 目: 模拟磁盘操作系统 专 业: 软件工程 班 级: 软件2班 姓 名: X X 学 号: 指导教师: XXX 成 绩: 计算机与信息工程学院2010年12月15日附件:课程设计内容 模拟磁盘操作系统 一:课程设计的目的1、掌握操作系统基本理论与管理方式;2、在算法基础上,解决实际的管理功能的问题,提高学生实际应用、编程的能力。3了解文件系统的一般原理。二: 课程设计的内容和要求1、涉及编程题目时,要求详细书写文档内容;2.问题分析及解决方案确定;3、形成编程思路;4、使用具体语言实现算法;5、上机调试程序;6、编写课程设计报告.三:
2、课程设计说明书和图纸要求3.1 设计题目与要求要求:1. 自定义磁盘操作系统命令解释器所需要的各种常用命令的数据结构;2. 至少具有显示文件、时间、日期、删除文件操作命令;3. 提供命令运行界面;4. 设置一定的内部命令和外部命令3.2 总的设计思想及系统平台、语言、工具等设计思想:通过用户输入不同的命令来调用不同的方法来实现磁盘操作系统,包括文件的增,删,查,改。平台:xp语言:java工具:eclipse,myeclipse3.3 数据结构与模块说明(功能与流程图)主程序流程图:显示子目录和子文件的流程图: 创建文件或文件夹的流程图复制文件或文件夹流程图四: 程序设计4.1 函数定义/ro
3、ot的get方法public String getRoot();/root的set方法public void setRoot(String root);/Start的构造方法public Start();/程序开始private void launch();/Deal的构造方法Deal(Start s,BufferedReader br);/输出子目录和子文件名public void showChildren();/改变根目录public void changeRoot(String type);/返回上级父目录public void back();/创建文件夹或文件public void c
4、reate();/打开文件方法public void open(String type);/复制文件或文件夹的选择方法public void copy(String filepath);/复制文件的方法public void copyFile(File src,File dec);/复制文件夹的方法 public void copyDir(File file,File file2);/显示文件夹结构的初始化方法public void show();/显示文件夹结构的方法public void list(File f, int level);/删除文件夹或文件的方法public void del
5、ete(File file);/文件重命名或文件夹重命名方法public boolean fileReName(String type);/文件或文件夹移动的方法public void move(String filepath);4.2 变量定义BufferedReader br = null; /输入流,用于接收用户的输入Deal deal;/对象名String type = null;/用户的选择的功能String root;/默认的根目录4.3 源程序Start.javaimport java.io.BufferedReader;import java.io.File;import ja
6、va.io.IOException;import java.io.InputStreamReader;public class Start private BufferedReader br = null;private String root =C:/Documents and Settings/Administrator;private Deal deal = null;/root的get方法public String getRoot() return root;/root的set方法public void setRoot(String root) this.root = root;pub
7、lic static void main(String args) new Start().launch();/Start的构造方法public Start() br = new BufferedReader(new InputStreamReader(System.in); deal = new Deal(this,br);/程序开始private void launch() try String type = null;while(true) System.out.println(*);System.out.println(root);type = br.readLine();if(typ
8、e.matches(w:) File file = new File(type);if(file.exists() this.setRoot(type);else System.out.println(文件目录不存在!);else if(type.matches(cds.) deal.back();else if(type.matches(cds.+) /cdsw1,(/w1,)*(/w1,.w1,)?deal.changeRoot(type);/-else if(type.equalsIgnoreCase(dir) deal.showChildren(); /对D盘无效else if(typ
9、e.equalsIgnoreCase(create) deal.create();else if(type.matches(opensw1,.w1,) deal.open(type); else if(type.matches(copys.1,) deal.copy(type);else if(type.equalsIgnoreCase(show) deal.show();else if(type.equalsIgnoreCase(delete) deal.delete(new File(root);deal.back();else if(type.matches(renames.1,)if(
10、deal.fileReName(type) deal.back();else if(type.matches(moves.+) deal.move(type);deal.back();else if(type.equalsIgnoreCase(help) System.out.println(x:-进入x盘);System.out.println(cd+空格+目录-进入子目录);System.out.println(cd+空格+.-返回上一级目录);System.out.println(dir-列出当前目录下的所有子目录和文件);System.out.println(create-创建文件夹或
11、文件);System.out.println(open+空格+文件名-打开文件);System.out.println(copy-复制当前文件或文件夹);System.out.println(move-移动当前文件或文件夹);System.out.println(show-列出当前目录下所有子目录和文件的结构);System.out.println(delete-删除当前文件夹或文件);System.out.println(rename+空格+目录名-重命名当前目录);System.out.println(rename+空格+文件名-重命名当前文件);System.out.println(he
12、lp-显示帮助信息);System.out.println(exit-退出);else if(type.equalsIgnoreCase(exit) System.exit(0);else System.out.println(输入的不是正确命令!); catch (IOException e) e.printStackTrace(); Deal.javaimport java.awt.Frame;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.Fil
13、eNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.Date;import javax.swing.JOptionPane;public class Deal private Start start = null;private BufferedReader br = null;/构造方法Deal(Start s,BufferedReader br) this.start = s;this.br = br;/输出子目录和子文件名public void sho
14、wChildren() File file = new File(start.getRoot();System.out.println(file.getAbsolutePath();if(file.exists() if(file.isDirectory() String str = file.list();for(int i=0;istr.length;i+) System.out.println(stri);else System.out.println(已到达文件末尾!);else System.out.println(输入的不是正确命令!);/改变根目录public void chan
15、geRoot(String type) String filepath = type.substring(3);File file = new File(start.getRoot()+/+filepath);if(file.exists() start.setRoot(start.getRoot()+/+filepath);else System.out.println(目录不存在!);/返回上级父目录public void back() String root = start.getRoot();if(root.matches(w:) System.out.println(已到达磁盘根目录
16、,无法继续返回父目录!);return ;else String backroot = root.substring(0,start.getRoot().lastIndexOf(/);start.setRoot(backroot);/创建文件夹或文件public void create() System.out.println(1.创建文件目录);System.out.println(2.创建文件);try String type = br.readLine();if(type.equals(1) System.out.println(请输入需要创建的文件目录,以/分隔);String msg
17、 = br.readLine();while(!msg.startsWith(/) System.out.println(文件目录必须以/开头);msg = br.readLine();File file = new File(start.getRoot()+ msg);if (file.exists() System.out.println(操作失败,文件目录已存在); else if (file.mkdirs() System.out.println(文件目录创建成功!); else System.out.println(文件目录创建失败!);else if(type.equals(2)
18、System.out.println(请输入文件名:);String fileName = br.readLine();while(!fileName.matches(w+.w+) System.out.println(请正确输入文件名的格式!);fileName = br.readLine();File file2 = new File(start.getRoot()+ / + fileName);if (file2.createNewFile() file2.setLastModified(new Date().getTime();System.out.println(文件创建成功!);
19、else System.out.println(操作失败);else System.out.println(输入的值不合法!); catch (IOException e) e.printStackTrace();/打开文件方法public void open(String type) System.out.println(type);File file = new File(start.getRoot()+/+type.substring(5);System.out.println(start.getRoot()+/+type.substring(5);if (file.exists() R
20、untime r = Runtime.getRuntime();try r.exec(cmd /c start +start.getRoot()+/+type.substring(5); catch (IOException e) System.out.println(文件拒绝访问!);return;System.out.println(文件打开成功!);System.out.println(文件名: + file.getName() + ,文件大小:+ file.length() + ,文件创建时间:+ new Date(file.lastModified().toString(); els
21、e System.out.println(文件不存在!);/复制文件或文件夹的选择方法public void copy(String filepath) String dscFilepath = filepath.substring(5);File file = new File(start.getRoot();File file2 = new File(dscFilepath);if(!file2.exists() System.out.println(目的文件夹不存在!+file2.getAbsolutePath();else if(file2.isDirectory()if(file.i
22、sDirectory() copyDir(file,file2);System.out.println(文件夹复制成功!);else if(file.isFile() copyFile(file,new File(file2,file.getName();System.out.println(文件复制成功!);else if(file2.isFile() System.out.println(您输入的不是一个目录!);/复制文件的方法public void copyFile(File src,File dec)FileInputStream fis = null;FileOutputStrea
23、m fos = null;byte buffer = new byte1024; /为了提高效率,设置缓存数组int temp = 0;try fis = new FileInputStream(src);fos = new FileOutputStream(dec);while(temp=fis.read(buffer)!=-1)fos.write(buffer, 0, temp); catch (FileNotFoundException e) System.out.println(文件夹未找到!);return; catch (IOException e) System.out.prin
24、tln(复制中出错!);return;finallytry if(fos!=null)fos.close(); catch (IOException e) e.printStackTrace();try if(fis!=null)fis.close(); catch (IOException e) e.printStackTrace();/复制文件夹的方法 public void copyDir(File file,File file2)new File(file2,file.getName().mkdir();File files = file.listFiles();for(File f:
25、files)if(f.isDirectory()copyDir(f,new File(file2,file.getName();if(f.isFile()copyFile(f,new File(new File(file2,file.getName(),f.getName(); /显示文件夹结构的初始化方法public void show() list(new File(start.getRoot(),1);/显示文件夹结构的方法public void list(File f, int level) StringBuilder preStr = new StringBuilder();for(
26、int i = 0; i level; i+) preStr.append(-);File childs = f.listFiles();for(File child : childs) System.out.println(preStr + child.getParentFile().getName()+|+child.getName();if(child.isDirectory() list(child, level+1);/删除文件夹或文件的方法public void delete(File file) if (!file.isDirectory() file.delete();Syst
27、em.out.println(成功删除文件: + file.getName(); else if (file.isDirectory() File fs = file.listFiles();for (File f : fs) delete(f);file.delete();System.out.println(成功删除文件夹: + file.getName(); /文件重命名或文件夹重命名方法public boolean fileReName(String type) String msg = type.substring(7);File file = new File(start.getR
28、oot();String backroot = start.getRoot().substring(0,start.getRoot().lastIndexOf(/);File file2 = new File(backroot + / + msg);if (file2.exists() System.out.println(重命名失败!,文件夹或文件名已存在!);return false;if (file.isDirectory() if (msg.matches(w+) if (file.renameTo(file2) System.out.println(文件夹重命名成功!);return true; else System.out.println(文件夹重命名失败!); else System.out.println(请输入有效字符!);return false; else if (file.isFile() if(msg.mat
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 47086-2026增强纤维和微纤维棉直径及其分布的测定数字光学扫描仪法
- 轧钢厂各工种考核制度
- 学校意识形态考核制度
- 专任教师育人考核制度
- 传染病培训与考核制度
- 筑炉管理人员考核制度
- 煤矿消防安全考核制度
- 院学生会干事考核制度
- 体检中心考勤考核制度
- 店长安全管理考核制度
- 小学班主任管理经验
- DL∕T 5776-2018 水平定向钻敷设电力管线技术规定
- 甲状腺护理教学查房
- 过年开销清单分析报告
- 中小学教师违反职业道德行为处理办法
- 不做教书匠青年教师读书交流活动感悟
- 评标专家专业分类标准
- 《学术规范和论文写作》课件全套 第1-10章 知:认识研究与论文写作 - 引文规范
- 传感器与自动检测技术课件
- 工程预结算课件
- 人教版八年级下物理第7、8单元测试题及答案
评论
0/150
提交评论