替换文件夹中txt某一个字符
public void testTH(){
String filePath = "F:\\代码\\extract-data\\storage-cassandra\\data";
String path = "F:\\代码\\extract-data\\storage-cassandra\\datax";
File fileDir = new File(filePath);
for (File file : fileDir.listFiles()) {
String newFileName = file.getName();
String newfilePath = path + File.separator + newFileName;
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader(file));
String linetxt = null;
StringBuilder result = new StringBuilder();
while ((linetxt = bufferedReader.readLine()) != null) {
String newconttent = linetxt.replace("普通用户","user");
result.append(newconttent);
File newfile = new File(newfilePath);
PrintStream ps = new PrintStream(new FileOutputStream(newfile, true));
ps.println(newconttent);
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}finally {
try {
bufferedReader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}