zoukankan      html  css  js  c++  java
  • java io流读取 和commons.io的使用

     前提:记事本里面一共有605个字

    1.使用BufferedReader和FileReader来读取txt里面的内容,用时相对短。读完记得关闭流br.close()

     2.指定UTF-8输出格式,使用FileInputStream,InputStreamReaderBufferedReader,时间也是瞬间,读完记得关闭流isr.close()和bf.close()

    3.使用commons.io里面的FileUtils.lineIterator来读取文件,时间也是一秒。。lineIterator.close()

    可到这里下载需要的commons.io文件:https://commons.apache.org/proper/commons-io/download_io.cgi

     4将EXAMPLE_TXT_PATH_WRINT的内容写到EXAMPLE_TXT_PATH_READ文件里面

    通过ByteArrayInputStream、ByteArrayOutputStream、TeeInputStream直接对字节来进行读写。。

     XmlStreamReader来读取文件的字符格式

    api:https://commons.apache.org/proper/commons-io/javadocs/api-2.0.1/index.html?org/apache/commons/io/LineIterator.html

    .IOCase判断某个字符串中是否以另一个字符串结尾,并且区分大小写

    api:https://commons.apache.org/proper/commons-io/javadocs/api-2.0.1/index.html?org/apache/commons/io/LineIterator.html

    package content.demo;
    
    import org.apache.commons.io.IOCase;
    import org.junit.Test;
    
    import java.io.IOException;
    
    /**
     * Created by 70486 on 2017/6/28 on 21:59.
     */
    
    public class testDemo3 {
        
        @Test
        public void setStart() throws IOException {
            
            String str1 = "This is a new String.";
            String str2 = "This is another new String, yes!";
            
            //SYSTEM :由当前操作系统确定的区分大小写的常数。
            //checkEndsWith:使用区分大小写的规则检查一个字符串是否以另一个字符串结尾。
            System.out.println("以字符串结尾(由系统区分大小写)Ends with string (case sensitive): " +
                    IOCase.SYSTEM .checkEndsWith(str1, "string"));
            
            System.out.println("以字符串结尾(由系统区分大小写)Ends with string (case sensitive): " +
                    IOCase.SYSTEM .checkEndsWith(str2, "yes"));
    
            //SENSITIVE:无论操作系统如何,区分大小写的常数。
            //checkEndsWith:使用区分大小写的规则检查一个字符串是否以另一个字符串结尾。
            System.out.println("以字符串结尾(区分大小写)Ends with string (case sensitive): " +
                    IOCase.SENSITIVE.checkEndsWith(str1, "string."));
            
            System.out.println("以字符串结尾(区分大小写)Ends with string (case sensitive): " +
                    IOCase.SENSITIVE.checkEndsWith(str2, "yes!"));
    
            //INSENSITIVE:无论操作系统如何,不区分大小写的常数。
            //checkEndsWith:使用区分大小写的规则检查一个字符串是否以另一个字符串结尾。
            System.out.println("以字符串结尾(不区分大小写)Ends with string (case insensitive): " +
                    IOCase.INSENSITIVE.checkEndsWith(str1, "string."));
            
            System.out.println("以字符串结尾(不区分大小写)Ends with string (case insensitive): " +
                    IOCase.INSENSITIVE.checkEndsWith(str2, "yes!"));
        }
    }
  • 相关阅读:
    rsyslog+loganalyzer配置
    Python字符串格式化
    awk
    haproxy配置
    CentOS7服务管理
    Nginx缓存
    父指针 子指针
    矩阵 特征向量
    指针的运算
    const 与指针 的用法
  • 原文地址:https://www.cnblogs.com/xiaodingdong/p/7237219.html
Copyright © 2011-2022 走看看