[HD-OCP17/21-Fundamentals Pg 532, Sec. 19.1.2 - reading-and-writing-binary-data]

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:

[HD-OCP17/21-Fundamentals Pg 532, Sec. 19.1.2 - reading-and-writing-binary-data]

Post by raphaelzintec »

why not starting by giving a simple example such as read txt file and print its content in terminal then write something inside a new file

what i mean is why starting explanation with bytes... we are humans we don't deal with bytes we don't understand them

Code: Select all

InputStream fis = new FileInputStream("C:\\Users\\batman\\Desktop\\ocp\\myfile.txt");
        int bite = fis.read();
        while (bite != -1) {
            char letter = (char) bite;
            System.out.print(letter);
            bite = fis.read();
        }
        fis.close();

        try (OutputStream fos = new FileOutputStream("C:\\Users\\batman\\Desktop\\ocp\\myfileout.txt")) {
            String s = "hello world";
            fos.write("hello world".getBytes());
        }

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

Re: [HD-OCP17/21-Fundamentals Pg 532, Sec. 19.1.2 - reading-and-writing-binary-data]

Post by admin »

Because writing text involves encoding.
Book is for programmers and programmers understand bytes :) .

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

Re: [HD-OCP17/21-Fundamentals Pg 532, Sec. 19.1.2 - reading-and-writing-binary-data]

Post by raphaelzintec »

yes and this forum is made for venting out your anger cuz its mentionned in the book

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

Re: [HD-OCP17/21-Fundamentals Pg 532, Sec. 19.1.2 - reading-and-writing-binary-data]

Post by admin »

That's true too :D

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 32 guests