文件的储存

来源:互联网 发布:个人发卡网源码授权 编辑:程序博客网 时间:2024/04/29 12:18
package hys;
import java.io.*;
public class hys {
    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);  
        BufferedReader bufred=new BufferedReader(instr); 
        OutputStreamWriter outstr=new OutputStreamWriter(System.out); 
        BufferedWriter bufwt=new BufferedWriter(outstr); 
        RandomAccessFile fisIn=new RandomAccessFile(FileName,"rw"); 
        try {
            System.out.print("请输入内容(按<Enter>键结束):\n");
            str=bufred.readLine(); 
            System.out.print("在路经"+FileName+"中存储内容...\n");
            fisIn.writeBytes(str); 
            System.out.print("输出内容:\n");
            bufwt.write(str); 
            bufwt.write((int)('\n'));
            bufwt.flush();
        }
        catch(IOException ex) {
            System.out.println("输入/输出异常!");
        }


    }


}


原创粉丝点击