天天看点

FileWriter和FileReader

//      FileOutputStream fos = new FileOutputStream("test_2.txt");
//      OutputStreamWriter osw = new OutputStreamWriter(fos);

        /*
         * FileWriter可以向给定的文件中写出字符
         * FileWriter不允许修改字符集,这个要注意。
         */
        FileWriter writer = new FileWriter("test_2.txt");
        BufferedWriter bw = new BufferedWriter(writer);

        bw.write("hello,你好啊");
        bw.write("AAAAA");
        bw.write("你好啊");
        bw.close();

//      FileInputStream fis = new FileInputStream("test_2.txt");
//      InputStreamReader isr = new InputStreamReader(fis);

        FileReader reader = new FileReader("test_2.txt");
        BufferedReader br = new BufferedReader(reader);

        String ss = br.readLine();
        System.out.println(ss);
           

继续阅读