...
|
...
|
@@ -4,6 +4,10 @@ package com.xkl.upsoft; |
|
|
import org.json.JSONObject;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -21,6 +25,31 @@ public class Data { |
|
|
data.generateJsonFormatReport();
|
|
|
}
|
|
|
|
|
|
public static String readTxtFile(String filePath) {
|
|
|
String line = "";
|
|
|
try {
|
|
|
String encoding = "UTF-8";
|
|
|
File file = new File(filePath);
|
|
|
if (file.isFile() && file.exists()) { //判断文件是否存在
|
|
|
InputStreamReader read = new InputStreamReader(
|
|
|
new FileInputStream(file), encoding);//考虑到编码格式
|
|
|
BufferedReader bufferedReader = new BufferedReader(read);
|
|
|
String lineTxt = null;
|
|
|
while ((lineTxt = bufferedReader.readLine()) != null && !lineTxt.equals("")) {
|
|
|
line = lineTxt;
|
|
|
break;
|
|
|
}
|
|
|
read.close();
|
|
|
} else {
|
|
|
System.out.println("找不到指定的文件");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("读取文件内容出错");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return line;
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void generateJsonFormatReport() {
|
|
|
JSONObject report = new JSONObject();
|
...
|
...
|
|