|
@@ -4,6 +4,10 @@ package com.xkl.upsoft; |
|
@@ -4,6 +4,10 @@ package com.xkl.upsoft; |
|
4
|
import org.json.JSONObject;
|
4
|
import org.json.JSONObject;
|
|
5
|
import org.junit.Test;
|
5
|
import org.junit.Test;
|
|
6
|
|
6
|
|
|
|
|
7
|
+import java.io.BufferedReader;
|
|
|
|
8
|
+import java.io.File;
|
|
|
|
9
|
+import java.io.FileInputStream;
|
|
|
|
10
|
+import java.io.InputStreamReader;
|
|
7
|
import java.text.DecimalFormat;
|
11
|
import java.text.DecimalFormat;
|
|
8
|
|
12
|
|
|
9
|
/**
|
13
|
/**
|
|
@@ -21,6 +25,31 @@ public class Data { |
|
@@ -21,6 +25,31 @@ public class Data { |
|
21
|
data.generateJsonFormatReport();
|
25
|
data.generateJsonFormatReport();
|
|
22
|
}
|
26
|
}
|
|
23
|
|
27
|
|
|
|
|
28
|
+ public static String readTxtFile(String filePath) {
|
|
|
|
29
|
+ String line = "";
|
|
|
|
30
|
+ try {
|
|
|
|
31
|
+ String encoding = "UTF-8";
|
|
|
|
32
|
+ File file = new File(filePath);
|
|
|
|
33
|
+ if (file.isFile() && file.exists()) { //判断文件是否存在
|
|
|
|
34
|
+ InputStreamReader read = new InputStreamReader(
|
|
|
|
35
|
+ new FileInputStream(file), encoding);//考虑到编码格式
|
|
|
|
36
|
+ BufferedReader bufferedReader = new BufferedReader(read);
|
|
|
|
37
|
+ String lineTxt = null;
|
|
|
|
38
|
+ while ((lineTxt = bufferedReader.readLine()) != null && !lineTxt.equals("")) {
|
|
|
|
39
|
+ line = lineTxt;
|
|
|
|
40
|
+ break;
|
|
|
|
41
|
+ }
|
|
|
|
42
|
+ read.close();
|
|
|
|
43
|
+ } else {
|
|
|
|
44
|
+ System.out.println("找不到指定的文件");
|
|
|
|
45
|
+ }
|
|
|
|
46
|
+ } catch (Exception e) {
|
|
|
|
47
|
+ System.out.println("读取文件内容出错");
|
|
|
|
48
|
+ e.printStackTrace();
|
|
|
|
49
|
+ }
|
|
|
|
50
|
+ return line;
|
|
|
|
51
|
+ }
|
|
|
|
52
|
+
|
|
24
|
@Test
|
53
|
@Test
|
|
25
|
public void generateJsonFormatReport() {
|
54
|
public void generateJsonFormatReport() {
|
|
26
|
JSONObject report = new JSONObject();
|
55
|
JSONObject report = new JSONObject();
|