Ignore a line while reading a file in java

前端 未结 3 621
粉色の甜心
粉色の甜心 2021-01-27 00:42

I have some code to read the lines from a file, I would like to recognize when the line starts or the fisrt character (not blank) is \'*\' and ignore it, so inside

3条回答
  •  清歌不尽
    2021-01-27 01:29

    Assuming the * marks and end of line comment, this loop will keep anything needed on the line before it.

        input = new BufferedReader(new FileReader(new File(finaName)));
        String line = null;
        char[] lineChars;
        while ((line = input.readLine()) != null) {
            lineChars = line.toCharArray();
            line = "";
            for(char c: lineChars){
                if(c == '*')break;
                line.concat(Character.toString(c));
            }
            if(!line.equals(""))
            String[] words = line.split(" ");           
        }
    

提交回复
热议问题