Java File IO-FileWriter(字符流写入File)

时间:2024-06-10 22:42:01
public static void main(String[] args) throws IOException {

        String filePtah = "D:\\Javaideaporject\\JavaBaseSolid8\\File\\test.txt";

        FileWriter fileWriter = new FileWriter(filePtah, true); //加true是追加 不加是覆盖

        String write = "哈哈哈";

        fileWriter.write(write.toCharArray()); 
        //write(int)
        //write(char[])
        //write(char[], off, len)
        //write(sring)
        //write(string,off,len) 

        fileWriter.close(); //一定要关闭 不然的话写不进去

 }