‫Hello and welcome back in this lecture, I'll show you how to read files engo the first step is to open
‫the file for reading and OS that open is just good for that file.
‫Comma Izabela Colon equals oh it's not open ended.
‫The name of the file test that I also create a file called Test That in the car and talking back actory.
‫And I'll write something in the file.
‫If there is any error, I handle the error by printing it and terminating the program.
‫And I also close the file using a Diffa statement.
‫When I saved the file, it will automatically import lock and OS packages, I'll only read a part of
‫the file into a bite slice, so I create the bite slice.
‫Vitalize Colin equals and I use the make function, slice, bite and the length, it contains only two
‫bites and that means I'll eat exactly two bites from the file.
‫The next step is to call a doctor with full function.
‫It will return an error if the file is smaller than the bite slice.
‫No bikes ride.
‫The air value column equals I owe that full.
‫The first argument is the file and the second argument, the bite slice.
‫And the error handling code.
‫Let's see how many bikes have been read, look, that printf number of bikes read.
‫Berson de Backslash in.
‫And the second argument is, no bikes read.
‫I've read into a bite slice, so I'll point out the bite slice log that printf.
‫They tarried.
‫Vasanth s backslidden.
‫And the second argument is the bite vitalize.
‫I am saving the fight and running the program.
‫And I've read the first two letters, so the first two bites, which are H and E!
‫In the next example, I'll show you how to read the entire contents of the file into a bite slice IO
‫util that read all will read every bite from the reader.
‫In this case, the file and we'll return a slice of unknown size.
‫I am opening another file and I am opening this may not go file file committable are equals.
‫These are existing variables.
‫So I use equals, not Courland equals.
‫Oh, it's not open.
‫And the current file may not go.
‫And the error handling code.
‫And I am closing the fight using a divorce statement.
‫And it's time to call it util that read all on the file variable data comida doubler colon equals I
‫owe util that read all.
‫And it takes is argument the fight.
‫And the error handling code now I can printout data is a string footprint if data is string biosynthesis.
‫Becs Leshin.
‫And data and the fact that printf.
‫Number of bikes, red.
‫Land of data.
‫I am saving the file and running the program.
‫And I see the entire contents of this file.
‫Back main theme for the statement and so on.
‫There is also a small error, and to see the number of bikes red I must use per to be pixelation.
‫I am saving the fight and running the program again.
‫And I've read 699 bites, another way to read the entire file is to use util dataset file, which also
‫reads a file into a bite.
‫Slice of this function will handle opening and closing the file.
‫It's very useful if you just need a quick way to read the entire contents of the file into a bite slice.
‫They take my doubler, he calls util that file.
‫And a valid path for the final test that the next.
‫Then comes the error handling code and fact that printf.
‫Data red percent is pixelation.
‫And the second argument that I am saving the file and running the program.
‫And we notice how I've read the entire file into a bite slice.