- 8
- 0
- 约4.37千字
- 约 6页
- 2019-11-15 发布于安徽
- 举报
.
.
实验五 输入输出流
一、实验目的
掌握文件的使用
掌握字节I/O流、字符类I/O流、缓冲流、数据流等常用流的使用。
熟悉对象流、RandomAccessFile类的使用。
二、实验内容
利用各种常用IO流的处理方法,编写Java应用程序。
三、实验步骤与要求
第1题 文件加密
编写一个Java应用程序,将已存在的扩展名为.txt的文本文件加密后存入另一个文本文件中。
package four;
import java.io.*;
public class file {
public static void main(String args[])
{
File readFile =new File(Student.txt),
writeFile =new File(Hello.txt);
String s=欢迎来到北京 welcome;
char b[]=s.toCharArray();
try{
FileWriter out=new FileWriter(readFile,true);
out.write(b);
out.close();
FileWriter tofile=new FileWriter (hello.txt);
for(int i=0;ib.length;i++)
{
b[i]=(char)(b[i]^w);
}
String secret=new String(b);
System.out.println(原文:+s);
System.out.println(密文:+secret);
tofile.write(secret);
tofile.close();
FileReader inOne=new FileReader(Hello.txt);
int t=0;
System.out.println(存入后:);
while((t=inOne.read(b,0,2))!=-1)
{ String str=new String(b,0,2);
System.out.println(str);
}
inOne.close();
}
catch (IOException e){
System.out.println(e);
}
}
}
第2题 读写基本类型数据
编写一个Java应用程序,将若干基本数据写入到一个文件,然后再按顺序读出。
package five;
/*第2题 读写基本类型数据
编写一个Java应用程序,将若干基本数据写入到一个文件,然后再按顺序读出。
*/
import java.io.*;
public class read {
public static void main(String args[])
{ try{
FileOutputStream os=new FileOutputStream(data.txt);
DataOutputStream outdata=new DataOutputStream(os);
outdata.writeInt(99);
outdata.writeShort(23);
outdata.writeDouble(23.34535342132);
outdata.writeFloat(3.123221312f);
outdata.writeLong(2132445);
outdata.writeChar(O);
outdata.writeByte(2);
outdata.writeBoolean(true);
}
catch(IOException e){ System.out.println( int: );}
try{
FileInputStream ns=new FileInputStream(data.txt);
DataInputStream intdata=new DataInputStream(ns);
System.out.println( int: +intdata.readInt());
System.out.println( short: +intdata.readShort());
Sy
您可能关注的文档
- 燃烧热-物化实验报告.doc
- 人教版高中历史必修一期中考试试卷(优质).doc
- 认识总体国家安全观3.doc
- 日产汽车点火电路.doc
- 日常防火常识.doc
- 肉与肉制品工艺学 名词解释.doc
- 如何打造初中语文高效课堂.doc
- 如何经营好奶茶店.doc
- 如何区分平翘舌字.doc
- 如何在MAPINFO中快速获取经纬度.doc
- 2025年北京市门头沟区中考一模英语试题.docx
- 2025年北京市门头沟区中考二模英语试题.docx
- 2025年北京市丰台区中考二模英语试题.docx
- 2025年中考英语考前冲刺模拟卷 (北京专用) 解析卷.docx
- 2025年中考英语考前冲刺模拟卷 (北京专用) 原卷.docx
- 2025年肩颈按摩仪行业社媒趋势数据分析.docx
- 2025年人身险行业信用回顾与2026年展望.docx
- 合同法买卖合同培训课件.ppt
- 2025年全球食物系统与SDG研究报告-食物供给、食者健康、生态平衡的整体治理.docx
- 2025下半年四川乐山市川投峨眉铁合金(集团)有限责任公司对考前自测高频考点模拟试题最新.docx
原创力文档

文档评论(0)