




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
9 2 1 文件加密 4 程序模板 程序模板 请按模板要求 将 代码 1 代码 6 替换为 Java 程序代码 SecretExample java import java io public class SecretExample public static void main String args File fileOne new File hello txt fileTwo new File hello secret char b new char 100 try FileReader in 代码 1 创建指向 fileOne 的字符输入流 FileWriter out 代码 2 创建指向 fileTwo 字符输出流 int n 1 while n in read b 1 for int i 0 i n i b i char b i a 代码 3 out 将数组 b 的前 n 单元写到文件 代码 3 out 关闭 in 代码 4 创建指向 fileTwo 的字符输入流 System out println 加密后的文件内容 while n in read b 1 String str new String b 0 n System out println str in 代码 5 创建指向 fileTwo 的字符输入流 System out println 解密后的文件内容 while n in read b 1 for int i 0 i n i b i char b i a System out printf new String b 0 n 代码 6 in 关闭 catch IOException e System out println e 9 2 2 给文件的内容添加行号 4 程序模板 程序模板 按模板要求 将 代码 1 代码 14 替换为 Java 程序代码 ReadExample java import java io public class ReadExample public static void main String args File file new File c 1000 hello txt File tempFile new File temp text try FileReader inOne 代码 1 创建指向文件 file 的输入流 BufferedReader inTwo 代码 2 创建指向 inOne file 的输入流 FileWriter tofile 代码 3 创建指向文件 tempFile 的输出流 BufferedWriter out 代码 4 创建指向 tofile 的输出流 String s null int i 0 s 代码 5 inTwo 读取一行 while s null i out write i s out newLine s 代码 6 inTwo 读取一行 inOne close inTwo close out flush out close tofile close inOne 代码 7 创建指向文件 tempFile 的输入流 inTwo 代码 8 创建指向 inOne file 的输入流 tofile 代码 9 创建指向文件 file 的输出流 out 代码 10 创建指向 tofile 的输出流 while s 代码 11 null inTwo 读取一行 out write s out newLine inOne close inTwo close out flush out close tofile close inOne 代码 12 创建指向文件 file 的输入流 inTwo 代码 13 创建指向 inOne file 的输入流 while s 代码 14 null inTwo 读取一行 System out println s inOne close inTwo close tempFile delete catch IOException e System out println e 9 2 3 文件读取与模式匹配 4 程序模板 程序模板 按模板要求 将 代码 1 代码 6 替换为 Java 程序代码 PatternExample java import java io import java util import java util regex public class PatternExample public static void main String args File file 代码 1 该文件是某一个 java 源文件 try FileReader firstIn 代码 3 创建指向 file 的字符输入流 BufferedReader secondIn 代码 4 创建指向 firstIn 缓冲流 StringWriter out 代码 5 创建指向内存的字符串输出流 String s null while s secondIn readLine null 代码 5 out 将 s 写入内存 String content 代码 6 out 获取曾写入到内存中的全部字符 firstIn close secondIn close out close Pattern p Matcher m p Ppile s 1 A Z w m p matcher content TreeSet tree new TreeSet while m find String str m group str str substring 1 tree add str Iterator iter tree iterator System out println file getName 使用了如下的类 while iter hasNext String item iter next System out println item catch IOException e System out println e 9 2 4 读写基本类型数据 4 程序模板 程序模板 按模板要求 将 代码 1 代码 21 替换为 Java 程序代码 NumberExample java import java io public class NumberExample public static void main String args int a1 12 a2 1180 long b 808080 float x1 3 14F x2 12 456F double d 1234 9876 boolean boo1 true boo2 false char c 我 File f 代码 1 创建文件 try FileOutputStream fos 代码 1 创建指向 f 文件输出流 DataOutputStream out data 代码 2 创建指向 fos 的数据输出流 代码 2 out data 将数据 a1 写入到文件 代码 3 out data 将数据 a2 写入到文件 代码 4 out data 将数据 b 写入到文件 代码 5 out data 将数据 x1 写入到文件 代码 6 out data 将数据 x2 写入到文件 代码 7 out data 将数据 d 写入到文件 代码 8 out data 将数据 boo1 写入到文件 代码 9 out data 将数据 boo2 写入到文件 代码 10 out data 将数据 c 写入到文件 catch IOException e try FileInputStream fis 代码 11 创建指向 f 文件输入流 DataInputStream in data 代码 12 创建指向 fis 的数据输入流 System out println 代码 13 in data 读取 int 整数 System out println 代码 14 in data 读取 int 整数 System out println 代码 15 in data 读取 long 整数 System out println 代码 16 in data 读取 float 数 System out println 代码 17 in data 读取 float 数 System out println 代码 18 in data 读取 double 数 System out println 代码 19 in data 读取 boolean 数据 System out println 代码 20 in data 读取 boolean 数据 System out print 代码 21 in data 读取 char 数据 catch IOException e 9 2 5 对象的写入与读取 4 程序模板 程序模板 按模板要求 将 代码 1 代码 9 替换为 Java 程序代码 ObjectExample java import java util import java io public class ObjectExample public static void main String args Calendar calendar1 Calendar getInstance 创建一个日历对象 Calendar calendar2 Calendar getInstance 创建一个日历对象 calendar1 set 1949 9 1 将日历时间设置为 1949 年 10 月 1 日 注意 9 表示十月 calendar2 set 2005 9 1 try File f 代码 1 创建一个名字为 a txt 的文件 FileOutputStream fileOut 代码 2 创建指向文件 f 的文件输出流 ObjectOutputStream objectOut 代码 3 创建指向文件 fileOut 的对象输出流 代码 4 objectOut 写对象 calendar1 到文件 代码 5 objectOut 写对象 calendar2 到文件 FileInputStream fileIn 代码 6 创建指向文件 f 的文件输入流 ObjectInputStream objectIn 代码 7 创建指向文件 fileIn 的对象输入流 Calendar cloneCalendar1 代码 8 objectOut 读出对象 Calendar cloneCalendar2 代码 9 objectOut 读出对象 cloneCalendar1 setTime new Date cloneCalendar2 set 9999 9 1 int 年 calendar1 get Calendar YEAR 月 calendar1 get Calendar MONTH 1 日 calendar1 get Calendar DAY OF MONTH System out printf ncalendar1 的日期 d d d 年 月 日 年 calendar2 get Calendar YEAR 月 calendar2 get Calendar MONTH 1 日 calendar2 get Calendar DAY OF MONTH System out printf ncalendar2 的日期 d d d 年 月 日 年 cloneCalendar1 get Calendar YEAR 月 cloneCalendar1 get Calendar MONTH 1 日 cloneCalendar1 get Calendar DAY OF MONTH System out printf ncloneCalendar1 的日期 d d d 年 月 日 年 cloneCalendar2 get Calendar YEAR 月 cloneCalendar2 get Calendar MONTH 1 日 cloneCalendar2 get Calendar DAY OF MONTH System out printf ncloneCalendar2 的日期 d d d 年 月 日 catch Exception event System out println event 9 2 6 使用 RandomAcessFile 类处理文件 4 程序模板 程序模板 按模板要求 将 代码 1 代码 8 替换为 Java 程序代码 RandomExample java import java io public class RandomExample public static void main String args 你好 File f new File hello txt try RandomAccessFile random 代码 1 创建指向文件 f 的 random 对象 代码 2 将 random 的读取位置定位在文件内容的开
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 柱子隔热保护施工方案(3篇)
- 汽贸园招商活动策划方案(3篇)
- 五一装修活动方案策划(3篇)
- 荷叶沟施工方案(3篇)
- 墙体围护施工方案(3篇)
- 团建打篮球活动方案策划(3篇)
- 企业活动策划实施方案(3篇)
- 安徽省宣城市绩溪县2023-2024学年高三下学期高考二模数学试卷及答案
- 写颁奖词的题目及答案
- 古代中国的农业经济特点分析:高中历史教案
- 上海海事大学工程热力学英文课件chapter1 Basicconception
- 呼吸系统疾病诊疗指南共识
- 2025年陕西高考化学试卷试题真题及答案详解(山西宁夏青海适用)
- 子宫腺肌症教学护理查房
- 操作手册/西门子/软件/Simotion Programming-MCC
- DBJ53T-44-2021云南省建筑工程资料管理规程
- 中国可见光通信项目创业计划书
- 五金件盐雾测试报告
- 肛管鳞状细胞癌临床诊疗要点
- JG/T 8-2016钢桁架构件
- 选择测试题大全及答案
评论
0/150
提交评论