IO流

package bbb;

import java.io.*;

public class ccc {
    public static void main(String[]args)throws IOException{
        int i=0;
        File file=new File("c:\\Users\\administratoa\\desktop\\文件接收柜\\\\data.txt");
        try{
            FileWriter fw=new FileWriter(file,true);
            FileOutputStream out=new FileOutputStream(file);
            String str="123qwe@#$软件工程";
            for(i=0;i<str.length()-4;i++){
                out.write(str.charAt(i));
            }
            for(;i<str.length()-4;i++){
                fw.write(str.charAt(i));
                out.close();
                fw.close();
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            FileInputStream in=new FileInputStream(file);
            byte[]buf=new byte[(int)(file.length())];
            in.read(buf);
            String str=new String(buf);
            System.out.println(str);
            in.close();
        }catch(IOException ioe){
            ioe.printStackTrace();
        }
    }
}

 

posted on 2019-07-05 11:07  万能G  阅读(102)  评论(0编辑  收藏  举报

导航