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!"));
        }
    }
  • 相关阅读:
    MySQL对于数据库应该如何如何配置安全问题了
    对于改善 MySQL 数据装载操作有效率的方法是怎样
    MySQL与SQL比较有那些区别呢
    Centos6.5和Centos7 php环境搭建如何实现呢
    php单例模式是怎么实现的呢
    PHP编写的图片验证码类文件分享方法
    PHP中header函数的用法及其注意重点是什么呢
    java正则表达式四种常用的处理方式是怎么样呢《匹配、分割、代替、获取》
    PHP弱类型安全问题的写法和步骤
    vs2010 使用IIS EXPRESS出错.
  • 原文地址:https://www.cnblogs.com/xiaodingdong/p/7237219.html
Copyright © 2011-2022 走看看