public static void main(String[] args) throws Exception {
InputStream in = new FileInputStream("C:/Users/Desktop/参考资料/minganciku/敏感词库表统计.xlsx");
Workbook wb0 = new XSSFWorkbook(in);
Sheet sheet = wb0.getSheetAt(0);
StringBuilder stringBuilder = new StringBuilder();
int i = 0;
try {
for (Row row : sheet) {
i += 1;
if (null != row && row.getCell(3) != null) {
row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
stringBuilder.append(row.getCell(3).getStringCellValue());
stringBuilder.append("\r\n");//换行字符
}
}
}catch (Exception e){
e.printStackTrace();
}
FileWriter fwriter = null;
try {
// true表示不覆盖原来的内容,而是加到文件的后面。若要覆盖原来的内容,直接省略这个参数就好
fwriter = new FileWriter("C:/Users/Desktop/参考资料/minganciku/mingan.txt", true);
fwriter.write(stringBuilder.toString());
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
fwriter.flush();
fwriter.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}