package lzy;
import  java.io.*;
public class lzy {
    public static void main(String[] args) throws IOException {
        File file = new File("lzywort.txt");
        String st = "12345abcdef@#%&*软件工程";
        if(file.exists()){   //判断该文件是否存在
            System.out.println("该文件存在");
        }
        else                 //该文件不存在,即创建文件
        {
            System.out.println("good good");
            try{
                    file.createNewFile();
                    System.out.println("该文件已创建");
            }catch(Exception e){
                e.printStackTrace();
            }
        }
        try {         //输入流
            FileWriter fw = new FileWriter(file);
            fw.write(st);
            fw.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {          //输出流
            FileReader in = new FileReader(file);
            char byt[] = new char[1024];
            int  len = in.read(byt);
            try {
                int len1 = in.read();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.out.println(new String(byt,0,len));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        
        
        
    }

}
posted on 2019-06-12 12:01  ZOne=w=  阅读(108)  评论(0编辑  收藏  举报