package liuzhi;
import java.io.*;
public class zhang {
static final String FileName="d:/student.txt";//定义文件的路径
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
String str;
InputStreamReader instr=new InputStreamReader(System.in);//定义输入文件类InputStreamReader
BufferedReader bufred=new BufferedReader(instr);//定义读入缓冲器BufferedReader
OutputStreamWriter outstr=new OutputStreamWriter(System.out);//定义输出文件类OutputStreamWriter
BufferedWriter bufwt=new BufferedWriter(outstr);//定义写入缓冲器BufferedWriter
RandomAccessFile fisIn=new RandomAccessFile(FileName,"rw");//定义随机读取类RandomAccessFile
try{
System.out.print("请输入内容(按<Enter>键结束):\n");
str=bufred.readLine(); //读入流对象通过调用方法readLine()实现按行读取信息
System.out.print("在路径"+FileName+"中存储内容...\n");
fisIn.writeBytes(str); //将读取的内容写入文件流对象fisIn中
System.out.print("输入内容:\n");
bufwt.write(str); //将信息强制输出
bufwt.write((int)('\n'));
bufwt.flush();
}
catch(IOException ex){
System.out.println("输入/输出异常!");
}
}
}
运行结果:
知识点: 1.字符流
2.字符流常用类
3.DateInput 接口
4.DateOutput 接口