国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Java 的 FileFilter文件過濾與readline讀行操作實例代碼

Java 的 FileFilter文件過濾與readline讀行操作實例代碼

2019-10-13 14:48java教程網 Java教程

這篇文章介紹了Java 的 FileFilter文件過濾與readline讀行操作實例代碼,有需要的朋友可以參考一下

代碼如下:


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;
    }
}        

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 色婷婷综合网 | 欧美日韩91 | 亚洲aⅴ天堂av在线电影软件 | 永久免费看黄网站 | 精品视频网站 | 欧美日韩在线精品 | 黄视频免费观看 | 一区二区免费在线观看 | 可以在线观看的av网站 | 国产精品视频播放 | 久久精品中文字幕 | 国产小视频在线 | 精品国产乱码久久久久久影片 | 青青草一区二区 | 国产成人网 | 国内自拍视频网 | 免费在线一区二区 | 91亚洲精品在线 | 黄a在线观看 | 天天操,夜夜操 | 午夜爱 | 免费成人在线观看视频 | 人人超碰免费 | 欧美在线小视频 | 国产精品美女久久久久久久久久久 | 91精品秘密在线观看 | 成人一区二区在线 | 激情欧美一区二区三区 | 精品第一区 | 久久综合另类激情人妖 | 国产精品a久久久久 | 亚洲精品专区 | 毛片在线一区二区观看精品 | 欧美中文字幕一区二区三区亚洲 | 亚洲国产精品成人 | 国产高清在线 | 久久久久亚洲 | 国产视频一区二区 | 色com| 综合久久综合久久 | 色狠狠久久av五月综合 |