Copy Code code as follows:
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 {
File filter, file path can use D:\\presstest\\test absolute path, also can use Src/test.
file[] files = new File ("src"). Listfiles (New FileFilter () {
Public Boolean accept (File arg0) {
if (Arg0.getname (). EndsWith (". txt")) {//select TXT file
return true;
}
return false;
}
});
FileInputStream is =null; Input stream Read file
BufferedReader Dr =null; Read rows
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/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;
}
}