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!"));
}
}
java io流读取 和commons.io的使用的更多相关文章
- java IO流读取图片供前台显示
最近项目中需要用到IO流来读取图片以提供前台页面展示,由于以前一直是用url路径的方式进行图片展示,一听说要项目要用IO流读取图片感觉好复杂一样,但任务下达下来了,做为程序员只有选择去执行喽,于是找了 ...
- Java (三)APACHE Commons IO 常规操作
上一篇:Java (二)基于Eclipse配置Commons IO的环境 例1:查看文件.文件夹的长度(大小). 1 import java.io.File; 2 3 import org.apach ...
- Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils
1.错误叙述性说明 警告: Could not create JarEntryRevision for [jar:file:/D:/MyEclipse/apache-tomcat-7.0.53/web ...
- java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream(转)
java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream 使用Tomcat的Manag ...
- java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream at org.apach ...
- Tomcat中使用commons-io-2.5发生的错误java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils
关键词:IntelliJ IDEA.Tomcat.commons-io-2.5.jar.java.lang.ClassNotFoundException: org.apache.commons.io. ...
- 报错:maven:java.lang.NoClassDefFoundError: org/apache/commons/io/Charsets
运行报错: maven:java.lang.NoClassDefFoundError: org/apache/commons/io/Charsets 找不到Charsets这个类 上网查了以后,是因为 ...
- java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream异常解决方法
使用Tomcat部署Servlet程序时,单步调试跟踪到: List<FileItem> itemList = sfu.parseRequest(request); 总是会报错:Java. ...
- Java (四)APACHE Commons IO 复制文件
上一篇:Java (三)APACHE Commons IO 常规操作 例1:复制文件 1 import java.io.File; 2 import java.io.IOException; 3 4 ...
随机推荐
- MySQL查看表结构及查看建表语句
查看表结构:desc 表名 mysql> use recommend; Database changed mysql> desc user; +--------------+------- ...
- msp430入门编程01
msp430单片机最小系统 msp430入门学习 msp430入门编程
- Sum-(最大子序列和)
http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=652&pid=1003 题目大意: 给你一个序列,你随便找一 ...
- eclipse bug之No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK
解决办法: 1.eclipse菜单 - Window - Preferences- Java - Installed JREs 将配置的JRE定位到JDK,例如JRE home:D:\Program ...
- jQuery源代码解析(1)—— jq基础、data缓存系统
闲话 jquery 的源代码已经到了1.12.0版本号.据官网说1版本号和2版本号若无意外将不再更新,3版本号将做一个架构上大的调整.但预计能兼容IE6-8的.或许这已经是最后的样子了. 我学习jq的 ...
- #!/usr/bin/env 脚本解释程序的作用
the Zimbu programming language http://www.zimbu.org/getting-started -------------------------------- ...
- Django学习系列之结合ajax
AJAX简介 什么是AJAX AJAX = 异步JavaScript 和 XML(Asynchronous JavaScript and XML) 通过在后台于服务器进行少量数据交换,AJAX可以使网 ...
- windows 7 忘記密碼,用“带命令行的安全模式”
net user administrator /active:yes net user tester /add net localgroup administrators tester /add
- C# 复制和克隆认识浅谈
如有雷同,不胜荣欣.若转载,请注明 在C#中,用HashTable,DataTable等复制和克隆浅谈,以下直接看样例 HashTable ht = null; ht = new HashTable( ...
- Android网络爬虫程序(基于Jsoup)
摘要:基于 Jsoup 实现一个 Android 的网络爬虫程序,抓取网页的内容并显示出来.写这个程序的主要目的是抓取海投网的宣讲会信息(公司.时间.地点)并在移动端显示,这样就可以随时随地的浏览在学 ...