Lab整理程序设计文件IO_第1页
Lab整理程序设计文件IO_第2页
Lab整理程序设计文件IO_第3页
Lab整理程序设计文件IO_第4页
Lab整理程序设计文件IO_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

题目1这个实验中会给出一个data.txt的数据文件,数据文件中每一行为一条记录,每条记录就是一个计算表达式,每个操作数用空格隔开,但有一些表达式是不合法的,比如参数个数不够或过多,参数无法从字符串转换成数字,没有对应的计算操作等,要求每次读到一条不合法的记录都要将相应的异常抛出并记录异常信息。而且异常信息是定制的而不是系统自动生成的。因此你们需要实现自己的异常类,并在产生异常的地方将异常信息记录下来并通过java的日志功能记录相关信息。(注意看后面的提示) 要求窗口程序要以文件浏览的方式将data.txt读入。如:下图:还有一个日志文件:打开runtime.log有如下信息提示: 1) 你需要重写以下几个异常类: NumberFormatException (字符串无法转换成数字) ArrayIndexOutOfBoundsException (参数过少) ArithmeticException (除数为0) Exception (这个类要被重写两次,一个用来抛出操作符错误异常,一个用来抛出参数过多异常,并需要主动抛出) 2) 如何记日志先引入一个包: import java.util.logging.*; 配置日志属性: 在lab文件中有一个文件叫:perties,你们需要将此文件烤到你们电脑上的某个位置,在这里我假设你们放在d盘根目录下: LogManager lMgr = LogManager.getLogManager();try FileInputStream fin =new FileInputStream(d:/perties); lMgr.readConfiguration(fin); catch(Exception ex) return; Logger log = Logger.getAnonymousLogger(); 通过上面这段代码你们可以获得一个日志。往日志中添加内容: log.warning(this.getMessage(); (此处的this为我重新的exception对象) 日志存放地点: perty中有一句话如下: java.util.logging.FileHandler.pattern = d:/runtime.log 这是生成的log文件的地方与名称,当然你们可以改成你们自己的路径也可以不改。题目2DiskBackup 磁盘备份n 设计一个applet/application, 实现任意磁盘的所有文件向另一个磁盘的拷贝(备份)n 如何获取磁盘的所有逻辑盘符?n 逻辑盘也是目录,使用File对象的isDirectory()方法,例如测试盘E是否存在可用(new File(“E:”).isDirectory()=true?n 文件拷贝n 用FileInputStream, FileOutputStream从指定文件获取I/O流n 套用BufferedInputStream, BufferedOutputStream提高效率n 文件I/O结束后,记得调用close()关闭流n 获取当前目录currentDirectory下所有文件:n (new File(currentDirectory).listFiles();n 使用递归方法解决嵌套目录的备份问题:n 备份方法DiskBackup(currentDirectory)n 对当前目录下的文件(非目录)进行备份n 对当前目录下的子目录subDirectory调用DiskBackup(subDirectory)界面要求n 2个下拉列表ComboBoxn 为实现任意盘间的拷贝, 在applet初始化时获取硬盘当前的所有逻辑盘符添加到2个列表中.n Buttonl Start Backup: 开始备份l Create Log File: 输出日志文件 n 日志文件l 将完成的所有备份情况保存在一个文件log.txt中(选做部分)n TextArea(有剩余时间选做)l 将完成的备份情况显示在文本域中(日志文件的前台显示),例如:“X:/*/*/ 已备份”l 如何同步显示备份情况?将备份方法的调用包含在线程里(不要求)n 二次备份时如何实现原备份基础上的动态备份?l 判断为新的文件或修改过的文件:备份l 判断文件自上次备份后未修改过:跳过l 判断上次备份文件包含有过期(不存在)文件:删除题目3字符串分析与解析(一):分析给定的文档(article.txt),抓取出所有的单词:要求:1)使用BufferedReader读入给定的文章。2)分别统计26个字母出现的次数。3)提取所有英文单词,并统计其出现次数,并根据出现次数排序。题目4从外部文件 words.txt 读入英语单词,忽略所有标点符号和数字,生成字符串数组,将字符串数组排序后按空格连接成新字符串,输出到外部文件 sorted.txt。 提示:使用 eclipse 的同学注意文件的路径。 题目5There are 2048 plain files in the directory which is named entry. We can classify them into three types:Type one: the content, which is always an integer, in this type of file is the filename of next file that you need to read.Type two: there is only one file of this type, and you need to find it out. You can find this file through the indication the content of type one. Type three: these files are useless.Now please begin with the file named 0 and find out the target file. Then print its content.题目6File IODownload the example.xls from FTP. Read this file using Java, make two instances of classPlayer from it, and save the two instances as a JSON file called example.json . You may find a skeleton program Player.java in FTP. You may need a 3rd-party library to help you read a Microsoft Excel file. Here is an example: Apache POI. And you can learn all you need to know about JSON file from Json Website. In this project, we only need to use a subset of JSON. Here is how it works:An array of objects: object1,object2,.An object: name1 : value1 , name2 : value2, .Here is an example: example.json name:player1, deposit:10000, cash:2000, position:23, direction:clockwise , name:player2, deposit:2000, cash:5000, position:1, direction:clockwise The example.json file contains an array of 2 objects. Each of the objects has 5 properties:name, deposit, cash, position, direction.题目7Network IOThe most exciting thing about Internet is that you can use any API you want through Internet. You can easily build a useful Application based on these APIs. Most of these APIs talk via JSON these days. For example, copy the following URL into your favourite Web Browser and studies the result:/data/2.5/weather?q=London,ukIt is not too difficult to guess from the URL and the return value that this Web API return the weather information of a given city. Feel free to change the arguments after the q= part. For example,/data/2.5/weather?q=Shanghai,cnWrite a Weather Report Java program of your own that shows the weather conditions of some major cities of China. For example: Please input the ID of the city you want to check: 1. 上海 2. 北京 3. 深圳 4.

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论