1
00:00:01,160 --> 00:00:01,790
Hi everyone.

2
00:00:01,790 --> 00:00:06,660
So in this lesson we are going to write the code for writing data to a fight.

3
00:00:06,840 --> 00:00:08,450
So let's see.

4
00:00:08,480 --> 00:00:10,290
So this is my folder.

5
00:00:10,640 --> 00:00:11,350
File handling.

6
00:00:11,360 --> 00:00:12,590
And this is my file.

7
00:00:12,620 --> 00:00:14,670
So writing into a file guard CBP.

8
00:00:14,720 --> 00:00:17,260
So that does open this filing.

9
00:00:17,330 --> 00:00:23,000
So this is the file now for writing data to a file first of all we have to include a File f a stream

10
00:00:24,340 --> 00:00:27,900
so f stream is filed stream.

11
00:00:27,910 --> 00:00:32,700
So now we have to create an object.

12
00:00:32,740 --> 00:00:40,290
So what is the name of the class output file stream and let's add the name of the objectives or office

13
00:00:41,010 --> 00:00:41,880
and what do you have to do.

14
00:00:41,880 --> 00:00:47,730
So you have to call the constructor for cutting the constructor to the name of the file is my file not

15
00:00:47,820 --> 00:00:58,890
the 60 and the second bedroom it is optional so you can give us truncate or you can give us append so

16
00:00:58,890 --> 00:01:00,330
truncate this by default.

17
00:01:00,330 --> 00:01:02,780
So let's leave truncate only.

18
00:01:02,880 --> 00:01:06,530
So I want to truncate to basically file doesn't even exist.

19
00:01:07,930 --> 00:01:14,450
Now let's say I want to insert some data so office let's say I want to insert that data off a student

20
00:01:14,480 --> 00:01:22,170
so that any of the student is Brock Lesnar or you can simply say Brock let's say I want to insert the

21
00:01:22,170 --> 00:01:23,250
roll number of Brock.

22
00:01:23,310 --> 00:01:24,680
So the roll number is 30.

23
00:01:24,690 --> 00:01:31,930
For example and let's say that gives a computer science student to the branch of CSC

24
00:01:39,910 --> 00:01:42,430
So initially this file might find out the 60.

25
00:01:42,460 --> 00:01:43,420
You can see.

26
00:01:43,420 --> 00:01:49,410
So this four lays empty this full list containing only one file so this file my file not the excuse

27
00:01:49,430 --> 00:01:50,220
does not exist.

28
00:01:50,340 --> 00:01:52,230
So if I will run this code what will happen.

29
00:01:52,240 --> 00:01:57,270
It will create this file and it will open that file and then it will insert the new time block today

30
00:01:57,300 --> 00:01:58,590
and CSC.

31
00:01:58,590 --> 00:02:00,030
So we'll let us know what program

32
00:02:03,750 --> 00:02:05,190
so we are not printing anything.

33
00:02:05,190 --> 00:02:07,110
So that's why the output is empty.

34
00:02:07,140 --> 00:02:10,590
And now let's see what is the situation of our folder.

35
00:02:10,710 --> 00:02:13,010
So my folders containing these two files.

36
00:02:13,320 --> 00:02:16,580
And this is the file that our program has created.

37
00:02:16,590 --> 00:02:18,150
This file was not present earlier.

38
00:02:18,510 --> 00:02:22,790
So now let us open this file and this is the data that we inserted.

39
00:02:22,810 --> 00:02:32,780
BLOCK The NCIC simple nullity what I want to do so let us insert some data here.

40
00:02:32,800 --> 00:02:39,820
So for example this wireless already containing some data hello world and let's say ABC be anything

41
00:02:40,420 --> 00:02:41,240
and let's say

42
00:02:44,170 --> 00:02:48,050
Okay so this is the situation of my file no.

43
00:02:48,070 --> 00:02:48,300
Okay.

44
00:02:48,310 --> 00:02:54,880
So this is the situation of my file no save.

45
00:02:54,960 --> 00:02:56,080
Now what I want to do.

46
00:02:56,160 --> 00:02:58,160
So I do not want to lose my data.

47
00:02:58,170 --> 00:03:01,430
So now this time you will and deprogram my file already exist.

48
00:03:01,530 --> 00:03:03,420
But this time I do not want to lose my data.

49
00:03:03,450 --> 00:03:10,960
So what I will do I will use append and now if you will insert this data.

50
00:03:10,990 --> 00:03:14,270
So this data will now be inserted in this file.

51
00:03:14,320 --> 00:03:18,130
So this time this file already exists and it is containing some data.

52
00:03:18,280 --> 00:03:22,220
And I want to insert my new data after that data.

53
00:03:22,230 --> 00:03:28,340
So I am using append so this data will get appended inside my file.

54
00:03:28,460 --> 00:03:30,900
So let's turn our program.

55
00:03:30,910 --> 00:03:31,120
Okay.

56
00:03:31,130 --> 00:03:33,640
So let's change the name so that you can understand.

57
00:03:33,640 --> 00:03:34,910
So the name is list not

58
00:03:37,670 --> 00:03:38,230
selectee

59
00:03:40,900 --> 00:03:44,350
so again now what output screen is empty because we are not printing anything.

60
00:03:45,070 --> 00:03:46,880
Now let's see our fault again.

61
00:03:46,900 --> 00:03:48,870
So this time the file already exists.

62
00:03:48,880 --> 00:03:50,290
So it would not create new file.

63
00:03:50,290 --> 00:03:55,270
Now let us open this file so this was our original data.

64
00:03:55,480 --> 00:04:00,850
And now this is the data that we inserted using our program.

65
00:04:00,850 --> 00:04:07,690
Now one thing that V4 got to do is basically after writing our program after doing all the work you

66
00:04:07,690 --> 00:04:09,900
have to call the function close.

67
00:04:10,000 --> 00:04:16,310
So if it's not close so clauses in big function of output files stained glass.

68
00:04:16,390 --> 00:04:17,890
So this is very important.

69
00:04:17,950 --> 00:04:19,410
You have to call this function.

70
00:04:19,480 --> 00:04:26,450
And so very good practice so I hope you know now how to write it down to a file.

71
00:04:26,520 --> 00:04:29,520
So in the next video we will learn how to read data from a file.

72
00:04:29,880 --> 00:04:31,920
So I will see you in the next video by.
