ImageVerifierCode 换一换
格式:DOCX , 页数:21 ,大小:208.95KB ,
资源ID:15052526      下载积分:5 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-15052526.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(java文件资料管理系统器.docx)为本站会员(b****1)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

java文件资料管理系统器.docx

1、java文件资料管理系统器Java程序设计实验报告年级、专业、班级2011级计科3班2011级计科3班姓名江唯伟张桉实验题目命令行文件管理器实验时间2013.10.14实验地点主教0414实验成绩 实验性质验证性 设计性 综合性教师评价:算法/实验过程正确; 源程序/实验内容提交 程序结构/实验步骤合理;实验结果正确; 语法、语义正确; 报告规范; 其他: 评价教师签名:一、实验目的运用面向对象程序设计思想,基于Java文件管理和I/O框架,实现命令行下的文件管理器。二、实验项目内容1、实现文件夹创建、删除、进入。2、实现当前文件夹下的内容罗列,能够根据文件名、日期、大小,类型进行排序。3、实

2、现文件拷贝和文件夹拷贝(文件夹拷贝指深度拷贝,包括所有子目录和文件)。4、实现指定文件的加密和解密。5、实现多个文件的压缩和解压缩。6、实现一个大文件的分割和合并。7、实现把项目导出为可执行的*.jar文件。三、实验过程或算法(源程序)要求:写明设计思想、程序的结构、功能关系图、类的说明并按照UML的规范画出类之间的关系图、程序执行流程图,最后是源代码。设计思想:主界面给出所有的选项,通过switch-case事件,来选择不同功能。运用到try-catch处理异常。文件的操作用到了:FileInputStream和FileOutputStream,BufferedInputStream和Buf

3、feredOutputStream,Scanner等流。程序的结构:src里共含有四个java文件,分别为压缩、解压缩、分割与合并、main和其余功能选项。功能关系图: 创建目录 删除目录 复制文件 复制目录 加密解密文件主界面 列出目录 重命名 文件的压缩与解压 文件的分割与合成 退出程序执行流程图: 开始 进入主界面 按下键盘上相应数字按钮 按下数字19 按下数字0 根据提示输入数据 退出 实现功能 是 否 是否继续?源代码:创建目录:class CreateFile CreateFile() try System.out.println(where to create? + please

4、 input the path:); Scanner s = new Scanner(System.in); String path = s.next(); File file = new File(path); if (file.exists() System.out.println(please input the filename! + 例如 F:/src/sb。txt); String name = s.next(); File f = new File(path + File.separator + name); f.mkdir(); System.out.println(succe

5、ss to create!); else System.out.println(the directory isnt exist!); catch (Exception e) e.printStackTrace(); 删除目录:class DeleteFile File path; public DeleteFile(File path) this.path = path; public void Delete(File path) File files = path.listFiles(); for (int i = 0; i files.length; i+) if (filesi.isD

6、irectory() Delete(filesi); else filesi.delete(); path.delete(); 复制文件:class CopyFile CopyFile(String source, String target) try File f1 = new File(source); File f2 = new File(target); FileInputStream inputFile = new FileInputStream(f1); FileOutputStream outputFile = new FileOutputStream(f2); byte b =

7、 new byte1024 * 10; int value = 0; while (value = inputFile.read(b) != -1) outputFile.write(b, 0, value); outputFile.flush(); outputFile.close(); inputFile.close(); catch (Exception e) e.printStackTrace(); 复制目录:class CopyDirectory public void copyFolder(String oldPath, String newPath) try (new File(

8、newPath).mkdirs(); File o = new File(oldPath); String file = o.list(); File temp = null; for (int i = 0; i file.length; i+) if (oldPath.endsWith(File.separator) temp = new File(oldPath + filei); else temp = new File(oldPath + File.separator + filei); if (temp.isFile() FileInputStream inputDir = new

9、FileInputStream(temp); FileOutputStream outputDir = new FileOutputStream(newPath + / + (temp.getName().toString(); byte b = new byte1024 * 10; int value; while (value = inputDir.read(b) != -1) outputDir.write(b, 0, value); outputDir.flush(); outputDir.close(); inputDir.close(); if (temp.isDirectory(

10、) copyFolder(oldPath + / + filei, newPath + / + filei); catch (Exception e) e.printStackTrace(); 列出目录:class ListDirectory ListDirectory(String path) File df = new File(path); if (!df.exists() | (!df.isDirectory() System.out.println(List failed!); System.out .println(path + / + contains below directo

11、rise or files); String files = df.list(); for (int i = 0; i 0) out.write(buffer, 0, r); cis.close(); is.close(); out.close(); public void decrypt(String file, String dest) throws Exception Cipher cipher = Cipher.getInstance(DES); cipher.init(Cipher.DECRYPT_MODE, this.key); InputStream is = new FileI

12、nputStream(file); OutputStream out = new FileOutputStream(dest); CipherOutputStream cou = new CipherOutputStream(out, cipher); byte buffer = new byte1024; int r; while (r = is.read(buffer) = 0) cou.write(buffer, 0, r); cou.close(); out.close(); is.close(); 压缩与解压缩:public class TestZIP public static v

13、oid zipFiles(File srcfile, File zipfile) try / ZipOutputStream类:完成文件或文件夹的压缩 ZipOutputStream out = new ZipOutputStream(new FileOutputStream( zipfile); for (int i = 0; i 0) out.write(buf, 0, len); out.closeEntry(); in.close(); out.close(); System.out.println(压缩完成.); catch (Exception e) e.printStackTra

14、ce(); public static void unZipFiles(File zipfile, String descDir) try ZipFile zf = new ZipFile(zipfile); for (Enumeration entries = zf.entries(); entries.hasMoreElements();) ZipEntry entry = (ZipEntry) entries.nextElement(); String zipEntryName = entry.getName(); InputStream in = zf.getInputStream(e

15、ntry); OutputStream out = new FileOutputStream(descDir + zipEntryName); byte buf1 = new byte1024; int len; while (len = in.read(buf1) 0) out.write(buf1, 0, len); in.close(); out.close(); System.out.println(entry); catch (Exception e) e.printStackTrace(); 分割与合并:public class FileDivisionUniter public

16、static final String SUFFIX = .txt; public static String divide(String fileName, long size) throws Exception File inFile = new File(fileName); if (!inFile.exists() | inFile.isDirectory() throw new Exception(指定文件不存在!); File parentFile = inFile.getParentFile();/ 获得被分割文件父文件,将来被分割成的小文件就存放在这个目录下 long file

17、Length = inFile.length();/ 取得文件的大小 if (size = 0) size = fileLength / 2; int num = (int) (fileLength + size - 1) / size);/ 取得分割后的小文件的数目 String outFileNames = new Stringnum;/ 存放分割后的小文件名 BufferedInputStream fis = new BufferedInputStream(new FileInputStream( inFile), 10 * 1024 * 1024); / 用10M的缓冲读取 Buffe

18、redReader reader = new BufferedReader(new InputStreamReader(fis); String s = reader.readLine(); / 读输入文件流的开始和结束下标 long inEndIndex = 0; int inBeginIndex = 0; / 根据要分割的数目分割文件 for (int outFileIndex = 0; outFileIndex fileLength) ? fileLength : inEndIndex; / 从输入流中读取字节存储到输出流中 for (; inBeginIndex inEndIndex;

19、 inBeginIndex+) out.write(reader.read(); out.close(); outFileNamesoutFileIndex = outFile.getAbsolutePath(); fis.close(); return outFileNames; public static String unite(String fileNames, String targerFileName) throws Exception File inFile = null; File outFile = new File(targerFileName); FileOutputSt

20、ream out = new FileOutputStream(outFile); for (int i = 0; i fileNames.length; i+) inFile = new File(fileNamesi); FileInputStream in = new FileInputStream(inFile); int c; while (c = in.read() != -1) out.write(c); in.close(); out.close(); return outFile.getAbsolutePath(); 四、实验结果及分析和(或)源程序调试过程(包含程序运行截图

21、)主界面:1.创建目录:2.删除目录:3.复制文件:4.复制目录:5.加密解密文件:6.进入目录:7.列出目录:8.重命名:9.对文件夹进行压缩与解压缩:10.对文件进行分割与合成:0.退出程序:程序运行成功。备注:1、教师在布置需撰写实验报告的实验前,应先将报告书上的“实验题目”、“实验性质”、“实验目的”、“实验项目内容”等项目填写完成,然后再下发给学生。2、教师在布置需撰写报告的实验项目时,应告知学生提交实验报告的最后期限。3、学生应按照要求正确地撰写实验报告:1) 在实验报告上正确地填写“实验时间”、“实验地点”等栏目。2) 将实验所涉及的源程序文件内容(实验操作步骤或者算法)填写在“

22、实验过程或算法(源程序)”栏目中。3) 将实验所涉及源程序调试过程(输入数据和输出结果)或者实验的分析内容填写在“实验结果及分析和(或)源程序调试过程”栏目中。4) 在实验报告页脚的“报告创建时间:”处插入完成实验报告时的日期和时间。5) 学生将每个实验完成后,按实验要求的文件名通过网络提交(上载)到指定的服务器所规定的共享文件夹中。每个实验一个电子文档,如果实验中有多个电子文档(如源程序或图形等),则用WinRAR压缩成一个压缩包文档提交,压缩包文件名同实验报告文件名(见下条)。6) 提交的实验报告电子文档命名为:实验序号(1位数字)_年级(四位数字不要“级”字)专业(缩写:计算机科学与技术专业(计科)、网络工程专业(网络)、信息安全专业(信息)、物联网工程(物联网)项目组成员(学号(八位数字)姓名)doc。如完成第1个Project,专业为“计算机科学与技术”,“网络工程专业”专业,项目组成员有:张三(学号20115676),李四(学号20115

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2