About Question enthuware.ocpjp.v17.2.3756 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
raphaelzintec
Posts: 167
Joined: Sun Apr 21, 2024 10:43 am
Contact:

About Question enthuware.ocpjp.v17.2.3756 :

Post 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); 
            }
        }

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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?

raphaelzintec
Posts: 167
Joined: Sun Apr 21, 2024 10:43 am
Contact:

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

Post 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

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests