数据处理日志
数据处理日志
package com.vfsd.core; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.nio.charset.Charset; import com.csvreader.CsvWriter; public class LXTxtDataToCsv { public static String[] headers = {"","开始时间","结束时间","开始时间","结束时间","路径节点数量","路径欧式长度","路径曼哈顿长度","原始节点数量","开始时间","结束时间","路径节点数量","路径欧式长度","路径曼哈顿长度","原始节点数来明"}; public static String[] content = {"","","","","","","","","","","","","","",""}; public static String txtFilePath = "D:\\pts_data\\2022100501\\data_2023010702.txt"; public static String csvFilePath = "D:\\pts_data\\2022100501\\data_2023010702.csv"; public static CsvWriter csvWriter = null; public static void main(String[] args){ csvWriter = new CsvWriter(csvFilePath,',', Charset.forName("UTF-8")); try { csvWriter.writeRecord(headers); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { readTxtFile(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { csvWriter.flush(); csvWriter.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("读写完毕..."); } /*** * * @throws Exception */ public static void readTxtFile() throws Exception { File txtFile = new File(txtFilePath); FileReader fileReaderObj = new FileReader(txtFile); BufferedReader bufferedReaderObj = new BufferedReader(fileReaderObj); String lineStr=""; boolean groupDataStart = true; String jiantu_start_time = ""; String jiantu_end_time = ""; String AStar_start_time = ""; String AStar_end_time = ""; String AStar_route_num = ""; String AStar_route_length1 = ""; String AStar_route_length2 = ""; String RRT_start_time = ""; String RRT_end_time = ""; String RRT_route_num = ""; String RRT_route_length1 = ""; String RRT_route_length2 = ""; while((lineStr=bufferedReaderObj.readLine())!=null) { if(lineStr.startsWith("=")) { groupDataStart = true; }else { groupDataStart = false; } if(groupDataStart) { //建图开始时间:09:16:22 建图结束时间:09:16:28 lineStr=bufferedReaderObj.readLine(); String[] jiantu_time = lineStr.split("时间:"); jiantu_start_time = jiantu_time[1].replaceAll(" ", "").replace("建图结束", ""); jiantu_end_time = jiantu_time[2].replaceAll(" ", ""); //A*开始时间:09:16:36 A*结束时间:09:16:37 lineStr=bufferedReaderObj.readLine(); String[] AStrt_time = lineStr.split("时间:"); AStar_start_time = AStrt_time[1].replaceAll(" ", "").replace("A*结束", ""); AStar_end_time = AStrt_time[2].replaceAll(" ", ""); //原始路径节点数量:15 lineStr=bufferedReaderObj.readLine(); String[] astar_route_num = lineStr.split(":"); AStar_route_num = astar_route_num[1].replaceAll(" ", ""); lineStr=bufferedReaderObj.readLine(); //A*路径实际长度:30189.9 A*路径曼哈顿长度:6362.07 lineStr=bufferedReaderObj.readLine(); String[] AStrt_route_length = lineStr.split(":"); AStar_route_length1 = AStrt_route_length[1].replaceAll(" ", "").replace("A*路径曼哈顿长度", ""); AStar_route_length2 = AStrt_route_length[2].replaceAll(" ", ""); //RRT开始时间:09:16:57 RRT结束时间:09:17:01 lineStr=bufferedReaderObj.readLine(); String[] rrt_time = lineStr.split("时间:"); RRT_start_time = rrt_time[1].replaceAll(" ", "").replace("RRT结束", ""); RRT_end_time = rrt_time[2].replaceAll(" ", ""); //原始路径节点数量:15 lineStr=bufferedReaderObj.readLine(); String[] rrt_route_num = lineStr.split(":"); RRT_route_num = rrt_route_num[1].replaceAll(" ", ""); lineStr=bufferedReaderObj.readLine(); //RRT路径实际长度:23706 RRT路径曼哈顿长度:6362.07 lineStr=bufferedReaderObj.readLine(); String[] rrt_route_length = lineStr.split("长度:"); RRT_route_length1 = rrt_route_length[1].replaceAll(" ", "").replace("RRT路径曼哈顿", ""); RRT_route_length2 = rrt_route_length[2].replaceAll(" ", ""); content[1] = jiantu_start_time; content[2] = jiantu_end_time; content[3] = AStar_start_time; content[4] = AStar_end_time; content[5] = AStar_route_num; content[6] = AStar_route_length1; content[7] = AStar_route_length2; content[8] = ""; content[9] = RRT_start_time; content[10] = RRT_end_time; content[11] = RRT_route_num; content[12] = RRT_route_length1; content[13] = RRT_route_length2; content[14] = ""; csvWriter.writeRecord(content); csvWriter.flush(); }else { continue; } } } }
##############################
QQ 3087438119