文档介绍:实验五输入输出处理
班级 B09513 姓名李广慧学号 20094051310 日期 2012-4-18 成绩评定
(1)掌握输入、输出流的概念和基本层次关系
(2)掌握字节流和字符流的定义及使用
(3)掌握文件管理以及文件操作的基本方法
Eclipse
1、从文件中读入一段英文短文,将此短文中连续的两个或多个空格删除,只保留一个空格,通过这样来规范英文短文格式,并将修改后的短文使用字符流方式输出到屏幕上和一个文本文件中。
编写一个简易的记事本程序。能够记录或查找记事内容。记录功能包括每次将记事内容写入到文件中,日期为当天日期;查找功能包括查找全部记事内容或按日期查找某天记事信息。
:
import .*;
public class FileMessage {
public static void main(String srgs[]) throws IOException {
String fname = "d:\\";
File f1 = new File(fname);
File f2 = new File("d:\\");
FileInputStream inStream = null;
FileOutputStream outStream = null;
try{
inStream = new FileInputStream(f1);
outStream = new FileOutputStream(f2);
}catch(IOException e){
("error :"+ e);
}
char ch;
int a = 1;
ch = (char)();
while(ch != '#'){
if(ch == ' '){
a -- ;
if(a >= 0){
a -- ;
(ch);
(ch);
}
}
else {
a = 1;
(ch);
(ch);
}
ch = (char)();
}
();
();
}
}
截图显示:
:
import .*;
import ;
import ;
public class FileRecord {
FileInputStream fi = null;
InputStreamReader isr = null;
BufferedReader br = null;
FileOutputStream fo = null;
OutputStreamWriter osw = null;
BufferedWriter bw = null