我的文本文件包含这样的行
FLTR TID:0000003756 RPC ID:0000108159 用户:补救应用服务
FLTR TID:0000003756 RPC ID:0000108159 用户:补救应用服务
FLTR TID:0000003756 RPC ID:0000108159 用户:ibsdr
FLTR TID:0000003756 RPC ID:0000108159 用户:Vinay.k@in.uni.com
FLTR TID:0000003756 RPC ID:0000108159 用户:Vinay.k@in.uni.com
FLTR TID:0000003756 RPC ID:0000108159 用户:wsdl
FLTR TID:0000003756 RPC ID:0000108159 用户:stefan.hummel@uni.com
我想将突出显示的单词存储在 Excel 工作表中的列中,并且我只想存储唯一的用户名.. 比如:
第 1 列....第 2列
S.NO ......用户名
1 ..................补救申请服务
2 .................. ibsdr
3 ..................维奈.k@in.uni.com
4 ........ wsdl
5 ..................... stefan.hummel@uni.com
这是我尝试过的
public class User {
static HSSFWorkbook hwb = new HSSFWorkbook();
static HSSFSheet sheet = hwb.createSheet("new sheet");
static HSSFRow rowhead = sheet.createRow((short) 0);
static HSSFRow row = sheet.createRow((short) 1);
static int count = 1;
public static void main(String [] args) {
try {
rowhead.createCell((short) 0).setCellValue("SNo");
rowhead.createCell((short) 1).setCellValue("USER NAME");
BufferedReader br = new BufferedReader(new FileReader("filter.log"));
String str = null;
String user = null;
while ((str = br.readLine()) != null) {
if (str.contains("FLTR")) {
user = str.substring(48, 75); // This is to get user names
count++;
store(user, count);
}
}
FileOutputStream fileOut = new FileOutputStream("D:/Excel.xls");
hwb.write(fileOut);
fileOut.close();
System.out.println("Your excel file has been generated!");
}
catch (Exception ex) {
System.out.println(ex);
}
}
private static void store(String user, int count) {
row.createCell((short) 0).setCellValue(count);
row.createCell((short) 1).setCellValue(user);
}
}
输出
S.NO.......用户名
17963......补救申请服务
在这个每当我执行这个程序时,只有第一个值被存储而不是所有值存储..我只想在这个 Excel 表中存储唯一的用户名..
请帮助我,在此先感谢