Printstream Пропуск печати первой строки в файле

У меня есть этот код:

    public static void main(String[] args) {
        try {

            String filePath = (args[0]);



            BufferedReader br = new BufferedReader(new FileReader(filePath));
            String strLine = br.readLine();
            //Read File Line By Line and Print the content on the console
             PrintStream out = new PrintStream(new FileOutputStream( //printing output to user specified text file (command line argument: outputfile)
                    args[1]+".txt"));


            while ((strLine = br.readLine()) != null) {
            char [] words = strLine.toCharArray();
            System.out.println (strLine);
                Arrays.sort(words);
                out.println(words);
            }
            //close the streams
            br.close();
            }
            catch(IOException e){
            System.err.println("An IOException was caught, Re-open program and enter correct number of arguments :"+e.getMessage());
            }

    }


}

Он делает то, что я хочу, но пропускает первую строку входного файла.

Скажем, например, входной файл содержал этот список слов: пока красный синий

это вывело бы: edr belu

и пропустить печать: бей

1 ответ

+ Изменить

String strLine = br.readLine();

в

String strLine = null;

Первая строка используется в текущей строке (а затем отбрасывается) в текущей версии, когда while ((strLine = br.readLine()) != null) выполняет.

Другие вопросы по тегам