Java 的 FileFilter文件过滤,readline读行操作
来源:互联网 发布:淘宝卖家扣分规则 编辑:程序博客网 时间:2024/05/19 14:38
package com.cjonline.foundation.evisa;import java.io.BufferedReader;import java.io.File;import java.io.FileFilter;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;import java.math.BigDecimal;public class Test { public static void main(String[] args) throws Exception { //文件过滤器,文件路径可以使用D:\\pressTest\\test绝对路径,也可以用src/test。 File[] files = new File("src").listFiles(new FileFilter() { public boolean accept(File arg0) { if(arg0.getName().endsWith(".txt")){//选择txt文件 return true; } return false; } }); FileInputStream is =null; //输入流读取文件 BufferedReader dr =null; //读行 for (File file : files) { System.out.println("---------【 file name : "+ file.getName() +"】----------"); is =new FileInputStream(file); dr=new BufferedReader(new InputStreamReader(is)); String[] strings = new String[]{"Total transferred:","Requests per second:","[ms] (mean)","Time per request:", "Transfer rate:","Failed requests:","Write errors:"}; BigDecimal[] BigDecimals = calPress(dr); int i=0; for (BigDecimal BigDecimal : BigDecimals) { System.out.println(strings[i]+" "+BigDecimal); i++; } System.out.println(); } dr.close(); is.close(); } private static BigDecimal[] calPress(BufferedReader dr) throws IOException { BigDecimal[] res = new BigDecimal[]{BigDecimal.ZERO,BigDecimal.ZERO,BigDecimal.ZERO,BigDecimal.ZERO ,BigDecimal.ZERO,BigDecimal.ZERO,BigDecimal.ZERO} ; String totalTrans; while((totalTrans = dr.readLine()) != null){ if (totalTrans.startsWith("Total transferred:")) { String[] st = totalTrans.split(" "); BigDecimal value = BigDecimal.valueOf(Double.valueOf(st[st.length-2])); res[0]=res[0].add(value); } if (totalTrans.startsWith("Requests per second:")) { String[] st = totalTrans.split(" "); BigDecimal value = BigDecimal.valueOf(Double.valueOf(st[st.length-3])); res[1]=res[1].add(value); } if (totalTrans.endsWith("[ms] (mean)")) { String[] st = totalTrans.split(" "); BigDecimal value = BigDecimal.valueOf(Double.valueOf(st[st.length-3])); res[2]=res[2].add(value); } if (totalTrans.startsWith("Time per request:") && !totalTrans.endsWith("[ms] (mean)")) { String[] st = totalTrans.split(" "); BigDecimal value = BigDecimal.valueOf(Double.valueOf(st[st.length-7])); res[3]=res[3].add(value); } if (totalTrans.startsWith("Transfer rate:")) { String[] st = totalTrans.split(" "); BigDecimal value = BigDecimal.valueOf(Double.valueOf(st[st.length-3])); res[4]=res[4].add(value); } if(totalTrans.startsWith("Failed requests:")){ String[] st = totalTrans.split(" "); BigDecimal value = BigDecimal.valueOf(Double.valueOf(st[st.length-1])); res[5]=res[5].add(value); } if(totalTrans.startsWith("Write errors:")){ String[] st = totalTrans.split(" "); BigDecimal value = BigDecimal.valueOf(Double.valueOf(st[st.length-1])); res[6]=res[6].add(value); } } return res; }}
0 0
- Java 的 FileFilter文件过滤,readline读行操作
- java 文件的过滤 FileFilter
- java的文件过滤FileFilter
- Java 文件过滤 FileFilter
- Java FileFilter 文件过滤
- Java 文件过滤 FileFilter
- 文件的过滤(FileFilter)
- FileFilter文件过滤
- Filter(二)——Java利用FileFilter过滤文件
- android过滤隐藏文件FileFilter
- android过滤隐藏文件FileFilter
- 润乾--Filefilter过滤含有多级子目录的特定文件
- 如何过滤目录下特定的文件(FileFilter)
- jdk——FileFilter文件过滤接口的应用
- java 读文件时,readline的问题
- 使用FileFilter过滤文件清理Maven仓库
- java使用FileFilter筛选文件
- JAVA文件工具类之——文件过滤(使用FileFilter 过滤zip、tar.Z、jasper、et、xml文件类型)
- 线性表之顺序表的结构与实现
- 线性表之单链表
- sharepoint 2010 页面添加footer方法 custom footer for sharepoint 2010 master page
- 循环单链表的结构和定义
- 数据结构之循环双链表的结构和实现
- Java 的 FileFilter文件过滤,readline读行操作
- proxool数据库连接池框架
- bat 批处理变量
- 数据结构之栈的定义
- 数据结构之队列
- 数据结构之二叉树
- 用java语言编写的简单二叉树
- NYOJ513 A+B Problem IV
- 根据GB2312编码表求汉字字节