java 文件的写入和读取

  //写入操作 方法1
    OutputStream f = new FileOutputStream("C:/j/j.txt");
           f.write("aaaaaaa".getBytes());
           f.close();

        //写入操作 方法2
        File fi = new File("C:/j/j2.txt");
        OutputStream fo = new FileOutputStream(fi);
        fo.write("this is abc".getBytes());
        //读取数据方法1
        //InputStream f3 = new FileInputStream("C:/j/j2.txt");
        //读取数据方法2
        File f4 = new File("C:/j/j2.txt");
        InputStream  f3 = new FileInputStream(f4);
        int size = f3.available();
        for(int i=0; i< size; i++){
            System.out.print((char)f3.read() + "  ");
        }
        f3.close();

 

posted @ 2017-09-08 14:48  甜菜波波  阅读(458)  评论(0编辑  收藏  举报