package com.liuyang.service;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
public class test {
public static void main(String[] args) {
// step 1: read the file
try (BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\86150\\Desktop\\test\\exam-data-2022.txt"))) {
String line;
/* each line of the file will be converted into an object and stored in a list */
List<UserExampleExam> userExampleExams = new ArrayList<>();
// step 2: read each line of the file
while ((line = br.readLine()) != null) {
// step 3: separate each line with a comma to form a new array
String[] data = line.split(",");
// step 4: encapsulate the array as an object
UserExampleExam userExampleExam = DataStitching(data.length, data);
// add the object to the list
userExampleExams.add(userExampleExam);
}
// step 5: list parent-child relationships based on id and managerId
List<UserExampleExam> newUserExampleExams = LoopOutput(userExampleExams);
// step 6: format the result style and write to the result file
output(newUserExampleExams);
} catch (IOException e) {
System.err.println("Failed to read file: " + e.getMessage());
}
}
/**
* file output
* @param
*/
private static void output(List<UserExampleExam> data) {
try (BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\Us
树形文件读取和导出
最新推荐文章于 2024-01-14 00:17:30 发布