读取text文本工具类
来源:互联网 发布:2016年网络电影票房 编辑:程序博客网 时间:2024/06/05 08:34
package com.avic.custom.controller.us.st;import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.List;import com.alibaba.fastjson.JSON;/** * 读取text文本工具类 * */public class ReadTextUtils{ /** * 读取text文件内容 * 一行一行进行读取操作 * @param filePath 文件路径 * @return List 每一行的日志记录 */ public static List<String> readTextToList(String filePath){ List<String> lists=new ArrayList<String>(); try {File file=new File(filePath);BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));BufferedReader buf=new BufferedReader(new BufferedReader(new InputStreamReader(bis,"utf-8"),5*1024*1024));String s = null;while ((s=buf.readLine())!=null) { if(s!=null){ //取出日志文件里json字符串 s=s.substring(s.indexOf("{\""), s.lastIndexOf("}")+1); lists.add(s); }}buf.close();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} return lists; } public static void main(String[] args) { List<String> readTextToList = ReadTextUtils.readTextToList("D:/logs/app.log"); for (String string : readTextToList) {System.out.println(string); } System.out.println("集合长度"+readTextToList.size()); }}
app.log日志文件
14:07:15.949 [qtp2027897550-46] INFO com.avic.custom.controller.us.st.OperationLogController - {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:87)] [2017-04-27 14:08:55,830] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:87)] [2017-04-27 14:09:12,787] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:87)] [2017-04-27 14:09:17,508] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}14:11:06.418 [qtp1269291543-46] INFO com.avic.custom.controller.us.st.OperationLogController - {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:87)] [2017-04-27 14:13:29,117] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:87)] [2017-04-27 14:13:35,281] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:87)] [2017-04-27 14:16:17,442] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:87)] [2017-04-27 14:18:56,604] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:87)] [2017-04-27 14:19:46,539] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:87)] [2017-04-27 14:20:16,863] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:88)] [2017-04-27 14:30:16,203] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","userId":6,"deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:88)] [2017-04-27 14:31:25,998] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","userId":6,"deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:88)] [2017-04-27 14:31:56,531] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","userId":"6","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:88)] [2017-04-27 14:32:35,393] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","userId":"6","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:88)] [2017-04-27 14:33:29,995] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","userId":"6","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}[com.avic.custom.controller.us.st.OperationLogController.operationLog(OperationLogController.java:88)] [2017-04-27 14:34:21,177] : {"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
运行结果:
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","userId":6,"deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","userId":6,"deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","userId":"6","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","userId":"6","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","userId":"6","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
{"operationJsp":"点赞页面","operation":67,"deviceSystem":1013333,"IP":"127.0.0.1","operationTime":"2016-03-07 20:20:30","deviceModel":"iPhone6s","device":"15dfab3fe6e396b0f2e5","operationRemark":"为商品520点赞了","network":"5G","operator":"注册","city":"北京朝阳区"}
集合长度17
- 读取text文本工具类
- jQuery - AJAX 读取text文本
- Unity读取Text文本案例
- SAP long text SAP长文本读取。
- SAP long text SAP长文本读取。
- SAP long text SAP长文本读取。
- SAP long text SAP长文本读取。
- C# 读取text内容并向text写入内容,对文本进行读写
- 自动化测试工具无法读取PB的sle.text,解决方案
- 读取TEXT
- 读取Text
- 文本操作工具类
- 文本转换工具类
- Cocos2D-x游戏开发之二十五:自定义文本读取工具类
- text.class.php.php文本操作类
- java.text.NumberFormat 工具类
- java.text.DecimalFormat 工具类
- 读取文本
- java -- String基本方法
- [转]Volly网络请求
- 理解Cookie和Session机制(转)
- 利用梦网云通讯实现 短信 验证码 发送 附带教程~~~
- UI绘制流程分析(源码级分析)
- 读取text文本工具类
- IDEA运行时动态加载页面
- 计算 SMP IRQ Affinity
- C++11线程安全队列和安全栈
- 2017.05.05回顾 关于决策边界的一些思考
- 页面引用bootstrap报错Bootstrap's JavaScript requires jQuery
- Travis CI用来持续集成你的项目
- Session实现原理
- Easy-33