private List<String> readListFromFile() {
List<String> list = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader("/tmp/list.txt"))) {
String tmpStr;
while ((tmpStr = reader.readLine()) != null) {
if (StringUtils.isNotBlank(tmpStr)) {
list.add(tmpStr);
}
}
} catch (Exception e) {
log.error("readListFromFile error, msg:{}", e.getMessage(), e);
}
return list;
}
public static void writeToFile(String fileName, Set<String> dataSet) throws Exception{
try (FileOutputStream out = new FileOutputStream(new File(fileName));
OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
BufferedWriter bufferedWriter = new BufferedWriter(writer)) {
for (String data : dataSet) {
bufferedWriter.write(data);
bufferedWriter.write("\r\n");
}
bufferedWriter.flush();
} catch (IOException e) {
e.printStackTrace();
}
}