Hi everyone.
So in this lesson we are going to write the code for writing data to a fight.
So let's see.
So this is my folder.
File handling.
And this is my file.
So writing into a file guard CBP.
So that does open this filing.
So this is the file now for writing data to a file first of all we have to include a File f a stream
so f stream is filed stream.
So now we have to create an object.
So what is the name of the class output file stream and let's add the name of the objectives or office
and what do you have to do.
So you have to call the constructor for cutting the constructor to the name of the file is my file not
the 60 and the second bedroom it is optional so you can give us truncate or you can give us append so
truncate this by default.
So let's leave truncate only.
So I want to truncate to basically file doesn't even exist.
Now let's say I want to insert some data so office let's say I want to insert that data off a student
so that any of the student is Brock Lesnar or you can simply say Brock let's say I want to insert the
roll number of Brock.
So the roll number is 30.
For example and let's say that gives a computer science student to the branch of CSC
So initially this file might find out the 60.
You can see.
So this four lays empty this full list containing only one file so this file my file not the excuse
does not exist.
So if I will run this code what will happen.
It will create this file and it will open that file and then it will insert the new time block today
and CSC.
So we'll let us know what program
so we are not printing anything.
So that's why the output is empty.
And now let's see what is the situation of our folder.
So my folders containing these two files.
And this is the file that our program has created.
This file was not present earlier.
So now let us open this file and this is the data that we inserted.
BLOCK The NCIC simple nullity what I want to do so let us insert some data here.
So for example this wireless already containing some data hello world and let's say ABC be anything
and let's say
Okay so this is the situation of my file no.
Okay.
So this is the situation of my file no save.
Now what I want to do.
So I do not want to lose my data.
So now this time you will and deprogram my file already exist.
But this time I do not want to lose my data.
So what I will do I will use append and now if you will insert this data.
So this data will now be inserted in this file.
So this time this file already exists and it is containing some data.
And I want to insert my new data after that data.
So I am using append so this data will get appended inside my file.
So let's turn our program.
Okay.
So let's change the name so that you can understand.
So the name is list not
selectee
so again now what output screen is empty because we are not printing anything.
Now let's see our fault again.
So this time the file already exists.
So it would not create new file.
Now let us open this file so this was our original data.
And now this is the data that we inserted using our program.
Now one thing that V4 got to do is basically after writing our program after doing all the work you
have to call the function close.
So if it's not close so clauses in big function of output files stained glass.
So this is very important.
You have to call this function.
And so very good practice so I hope you know now how to write it down to a file.
So in the next video we will learn how to read data from a file.
So I will see you in the next video by.