[HD-OCP17/21-Fundamentals Pg 532, Sec. 19.1.2 - reading-and-writing-binary-data]
Posted: Tue Oct 01, 2024 3:12 pm
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
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());
}