Hi everyone.
So in this lesson we will learn how to read from a file.
So for example this is your file.
My file not the 60 and let's say it is containing somebody down.
So let's say this containing Hello World and then let's say it is containing integer 5.
So this is the date that at this present in this fight my file not the 60.
So for reading the detail from this fight again.
So first of all we have to include the file so hash include file stream.
So this is my domain.
Now what I have to do so basically first of all we have to create the object of if stream class i.e.
if a stream input file is stream class let's say the name of the object is in fine.
We're digging can do so you will call the concept and you will give the file name.
So my file not the 60.
Now one important thing it is basically Liesel.
This file my file not the 60.
So this file must exist because it will not create a new file.
Now there is one more way to open the file so first is during the constructor.
Second is basically you create an object.
So let's say if stream the object is in file two and there's a function open.
So what you gonna do.
You can call the function open so inviting to dot open and then you can give the name of the file the
file that you want to open.
So I want to open this file and the name is my filing not the 60.
So there are two ways of opening the file first is using deconstruct.
Second is basically using the open function simple now.
So there might be a situation that my file does not exist.
So what will happen.
You can write if condition.
So if
in file do so if this file does not exist.
So this condition will become true.
You can do so you can write C out file does not exist.
So this in file is actually a true false value.
So if the file does not exist then you can print the file does not exist.
So you can check also.
Now there is one more function to check first is using this method.
And second is basically you have a function is open so you can write it like this.
If
in file Dart is open.
So this is a function is open it will return true.
It will identical in value true or false.
So if the file does not exist then you can write the same statement that file does not exist
so you can use this way to check whether file exists or not.
Or you can use this way to check whether my file exists or not Now what I want to do.
So I want to read this file.
So what is the format.
So first of all you should know the format in which order the data is updating.
So first is a string.
Second is actually integer.
So what do we do.
First thing is a string.
So you will create a variable string SDR for storing Hallowell and then you will create an in danger
to store the digital value faith.
Okay.
So one important thing here is basically you should know the format the order in which the data is appearing
in your text file.
So what do you do.
So you will use this object for example in file 2 I'm using in value or you can use in file.
You can use any one of them.
So for example if I'm using in file so I will write it like this in file
SDR.
Similarly in file I now after this what you can do.
So after this you can print your data.
So see out SDR and line.
And similarly you can print your digital value which is five
now after adding the compute data.
I would reach and of the file.
So this is end of file.
Now I've a function and a file to check whether you reach an end of the file or not.
So basically you can use this function.
So if in file you will call this function.
End of file E or F..
Now this function will return true or a false value so this function will again a boolean value.
So if it is returning true that means I have reached the end of the file so you can print a message
like and a file reached now after doing all the work that you want to do with the file.
The most important thing is basically you have to close the connection.
So you have to call the function close.
So I will call in file dot close.
And similarly you can also call in file to dart close.
So this is all about reading from a fine.
Now one important thing here is basically.
So there are two modes actually so you can use a us in and the second mode is basically us out.
So us in mode.
So this is actually for reading the data and I use out is actually for writing the data.
So we call these flags.
So these are called flags or you can call them modes but I am using input file stream so input files
stream that means that automatically means that I want to use this when I want to basically read.
So that's why you do not need to mention the flags.
I'm repeating myself.
There are actually two types of flag input and output.
You want to read or you want to write but since I'm using input file stream then it is obvious that
I want to perform the operation.
So that's why you do not need to mention these flags any of these flags.
So in the next trade deal we will write the code I will see on the next one but I.