zoukankan      html  css  js  c++  java
  • JavaIO流学习总结-FileReader和FileWriter基本操作练习

    package io;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    /*
     * 修改日期:2020/04/05
     * 修改人:牟松
     * 字符流FileReader和FileWriter基本操作练习
     */
    public class ceshi {
     public static void main(String[] args)
     {
       try {
       //实例化字符输入流对象,如何只是读取文件内容则不能实例化输出流对象。
       FileReader inputstream=new FileReader("ceshi.txt");
       //实例化字符输出流对象,加入参数true则为添加,不覆盖文本中的内容。
       FileWriter outputstream=new FileWriter("ceshi.txt");
      
       /*try {
        //将文本内容全部写入文件中,并读出
        char[] string=new char[1024];
        outputstream.write("测试文本");
        outputstream.close();
        inputstream.read(string);
        System.out.println(new String(string));
        inputstream.close();
       } catch (IOException e) {
         e.printStackTrace();
       }*/
        
        /*//InputStreamReader常用的三个read方法
        char[] string=new char[1024];
        char[] string1=new char[1024];
        int lenth=inputstream.read();    //调用返回值为int方法之后执行后面的语句第一个字符会消失
        inputstream.read(string);          
        inputstream.read(string1, 0, 4); //第一个为字符数组,第二个为起始下标,第三个参数为读取个数
        System.out.println("内容长度:"+lenth);
        System.out.println("string:"+new String(string));
        System.out.println("string1内容:"+new String(string1));
        inputstream.close();*/
       
        /*//OutputStreamWriter常用的wirte方法
        outputstream.write("测试文本");
        outputstream.write("测试文本", 0, 3);  //第一个参数为文本,第二个为起始下标,第三个参数为写入长度
        outputstream.close();*/
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
    }
  • 相关阅读:
    [BAT]cmd命令之 cd /d %~dp0
    用Fiddler抓到的报文Content-Type: application/x-www-form-urlencoded,怎样解析?
    HDU 2646 栈的应用 STL
    Codeforces Round #332 (Div. 2)B. Spongebob and Joke
    Codeforces Round #311 (Div. 2)B. Pasha and Tea二分
    HDU4022 Bombing STL
    Codeforces Round #331 (Div. 2) C. Wilbur and Points
    Codeforces Round #331 (Div. 2) B. Wilbur and Array
    Codeforces Round #331 (Div. 2) A
    HDU5533(水不水?)
  • 原文地址:https://www.cnblogs.com/musong1998/p/12639902.html
Copyright © 2011-2022 走看看