Page 1 of 1

About Question enthuware.ocpjp.v17.2.3756 :

Posted: Sun Feb 09, 2025 5:49 am
by raphaelzintec
why this works with FileReader i learned that this way works only with BufferedReader

Code: Select all

 char[] buf = new char[5];
        try(FileReader fr = new FileReader("C:\\Users\\Downloads\\test1.txt");
            FileWriter fw = new FileWriter("C:\\Users\\Downloads\\test2.txt")){
            int count = 0;
            while( (count = fr.read(buf)) != -1){                 
                fw.write(buf, 0, count); 
            }
        }

Re: About Question enthuware.ocpjp.v17.2.3756 :

Posted: Sun Feb 09, 2025 8:41 am
by admin
I am not sure I understand your question. Which part of the above code are you asking about - the try-with-resource part, the fr.read call, fw.write call, or something else?

Re: About Question enthuware.ocpjp.v17.2.3756 :

Posted: Sun Feb 09, 2025 9:12 am
by raphaelzintec
i tought this way was only made for BufferedReader, but actually FileReader can also use this way, BufferedReader has only readLine that FileReader has not

so i understand better