import java.io.*;
public class Rs {
static final String FileName="d:/student.txt"; //定义文件路径
public static void main(String[] args) throws IOException{
String str;
InputStreamReader instr=new InputStreamReader(System.in); //定义输入文件类InputStreamReader
BufferedReader buffed=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.println("请输入内容(按<Enter>键结束):\n");
str=buffed.readLine(); //读入流对象通过调用方法readLine()实现按行读取信息
System.out.println("在路径"+FileName+"中存储内容...\n");
fisIn.writeBytes(str); //读取的信息写入文件流对象fisIn中
System.out.println("输出内容:\n");
bufwt.write(str); //将信息强制输出
bufwt.write((int)('\n'));
bufwt.flush();
}
catch(IOException ex){
System.out.println("输入/输出异常!");
}
}
public class Rs {
static final String FileName="d:/student.txt"; //定义文件路径
public static void main(String[] args) throws IOException{
String str;
InputStreamReader instr=new InputStreamReader(System.in); //定义输入文件类InputStreamReader
BufferedReader buffed=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.println("请输入内容(按<Enter>键结束):\n");
str=buffed.readLine(); //读入流对象通过调用方法readLine()实现按行读取信息
System.out.println("在路径"+FileName+"中存储内容...\n");
fisIn.writeBytes(str); //读取的信息写入文件流对象fisIn中
System.out.println("输出内容:\n");
bufwt.write(str); //将信息强制输出
bufwt.write((int)('\n'));
bufwt.flush();
}
catch(IOException ex){
System.out.println("输入/输出异常!");
}
}
}
知识点:1、字符流
2、字符流 常用类
3、DateInput接口
4、DateOutput接口