I want to read particular string from a text file and store them in Excel sheets

前端 未结 4 829
遇见更好的自我
遇见更好的自我 2021-01-24 04:02

My Text file Contains line like this

FLTR TID: 0000003756 RPC ID: 0000108159 USER: Remedy Application Service

FLTR TID: 0000003756 RPC ID: 0

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-24 04:38

    public class UniqueUSER {

    static HSSFWorkbook hwb=new HSSFWorkbook();

    static HSSFSheet sheet = hwb.createSheet("new sheet");

    public static void main(String[]args) throws IOException

    {

    HSSFRow row;

    HashSet names = new HashSet<>();

    BufferedReader br=new BufferedReader(new FileReader("simle.log"));

    PrintStream out=new PrintStream("D:/Excel.xls");

    String str=null;

    int count=0;

    while((str=br.readLine())!=null) {

    if(str.contains("FLTR"))

    {

    String user=str.substring(97, 135);

    count++;

    names.add(user);

    HSSFRow row1= sheet.createRow((short)count);

    row1.createCell((short) 0).setCellValue("names");

    }

    }

    Iterator itr=names.iterator();

    while(itr.hasNext()) {

    out.println(itr.next());  
    

    }

    }

    }

提交回复
热议问题