Page 1 of 1

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

Posted: Tue Oct 01, 2024 3:12 pm
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());
        }

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

Posted: Tue Oct 01, 2024 5:31 pm
by admin
Because writing text involves encoding.
Book is for programmers and programmers understand bytes :) .

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

Posted: Tue Oct 01, 2024 6:07 pm
by raphaelzintec
yes and this forum is made for venting out your anger cuz its mentionned in the book

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

Posted: Tue Oct 01, 2024 6:59 pm
by admin
That's true too :D