package com.heima.kaojiuyebanlianxiti;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class Demo19 {
/**
* 题目六:在c盘下有一个txt文件,里面的文本内容包含”tmd”,”TMD”,”SB”等关键词,要求把读取出来的文本数据中
* ”TMD”、”SB”的敏感字符以”**”或”***”代替,然后再输出到D盘的change.txt文本中
* @throws IOException
*/
public static void main(String[] args) throws IOException {
ArrayList<String> list = new ArrayList<>();
BufferedReader br = new BufferedReader(new FileReader("f:/aaa.txt"));
String len;
while ((len = br.readLine()) != null) {
String str = len.replaceAll("SB", "**");
str = str.replaceAll("sb", "**");
str = str.replaceAll("TMD", "***");
str = str.replaceAll("tmd", "***");
list.add(str);
}
br.close();
BufferedWriter bw = new BufferedWriter(new FileWriter("f:/change.txt"));
for (String s : list) {
bw.write(s);
bw.newLine();
}
bw.close();
}
}
|