Read one line of a csv file in Java

后端 未结 6 2000
Happy的楠姐
Happy的楠姐 2021-01-21 16:59

I have a csv file that currently has 20 lines of data. The data contains employee info and is in the following format:

first name, last name, Employee ID

So one

6条回答
  •  无人及你
    2021-01-21 17:34

    For reading large file,

    log.debug("****************Start Reading CSV File*******");
        copyFile(inputCSVFile);
        StringBuilder stringBuilder = new StringBuilder();
        String line= "";
        BufferedReader brOldFile = null;
        try {
            String inputfile = inputCSVFile;
            log.info("inputfile:" + inputfile);
            brOldFile = new BufferedReader(new FileReader(inputfile));
            while ((line = brOldFile.readLine()) != null) {
                //line  =   replaceSpecialChar(line);
                /*do your stuff here*/
                stringBuilder.append(line);
                stringBuilder.append("\n");
            }
    
            log.debug("****************End reading CSV File**************");
        } catch (Exception e) {
            log.error(" exception in readStaffInfoCSVFile ", e);
        }finally {
            if(null != brOldFile) {
                try {
                    brOldFile.close();
                } catch (IOException e) {
                }
            }
        }
        return stringBuilder.toString();
    

提交回复
热议问题