All language subtitles for 5. Creating a File and Reading from a File

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,210 --> 00:00:07,680 What is going on, guys, in this video, we are going to take a quick look and to see how we can work 2 00:00:07,680 --> 00:00:13,980 with opening files for a writing, reading and so on and so forth, and basically how the steps are 3 00:00:14,400 --> 00:00:15,960 made behind the scenes. 4 00:00:16,380 --> 00:00:24,480 So for that, I would like us to go to your project, click right, click on it and open folder in File 5 00:00:24,480 --> 00:00:25,190 Explorer. 6 00:00:25,560 --> 00:00:32,230 I would like us to take a look at how basically the project looks behind the scenes. 7 00:00:32,260 --> 00:00:38,580 OK, so if you're using Visual Studio, that's how you approach it. 8 00:00:38,580 --> 00:00:45,480 If you're using code blocks or clips, basically go to the folder containing your project. 9 00:00:45,630 --> 00:00:48,500 OK, so this is the folder containing my project. 10 00:00:48,750 --> 00:00:52,260 Here is the main dachsie file, which is this one. 11 00:00:53,250 --> 00:01:02,820 And basically what I'm going to show you now is that I will create a new file just right in this folder, 12 00:01:02,820 --> 00:01:04,650 in the folder of the project. 13 00:01:04,680 --> 00:01:06,270 OK, so. 14 00:01:07,930 --> 00:01:10,230 Let us start with a simple example. 15 00:01:11,390 --> 00:01:16,970 So step one will remain the same, step two, we will create a new file. 16 00:01:17,330 --> 00:01:21,590 So basically what what name should we give to these file? 17 00:01:21,600 --> 00:01:22,770 Let's call it? 18 00:01:22,820 --> 00:01:23,380 I don't know. 19 00:01:23,540 --> 00:01:34,700 My first file dot dxp, which will represent here, you can see the file name and we will also do what 20 00:01:34,700 --> 00:01:35,260 should we do? 21 00:01:35,270 --> 00:01:36,550 Let's remove this complaint. 22 00:01:36,740 --> 00:01:37,600 What should we do? 23 00:01:37,610 --> 00:01:41,810 We should specify that we create these file for writing. 24 00:01:42,380 --> 00:01:42,920 All right. 25 00:01:43,520 --> 00:01:45,080 Then we will make sure that. 26 00:01:46,100 --> 00:01:55,010 We are the opening process was successful, so let's just remove it, remove this one, so let's go 27 00:01:55,010 --> 00:02:01,050 the other way around and ask if P equals two now if that's the case, right. 28 00:02:01,070 --> 00:02:10,300 If that's the case, then the file opening file opening has failed. 29 00:02:10,790 --> 00:02:14,480 And if that's the case, we would like to I don't know, let's say printf. 30 00:02:14,750 --> 00:02:15,410 I don't know. 31 00:02:15,980 --> 00:02:19,610 The file was not found, OK. 32 00:02:19,610 --> 00:02:28,640 Or basically the the opening opening of the file has failed. 33 00:02:29,180 --> 00:02:39,230 OK, so we treat this situation because we said that there may be times when we would wouldn't have 34 00:02:39,230 --> 00:02:41,530 the option to open the file. 35 00:02:41,540 --> 00:02:44,360 OK, so we would like to treat it. 36 00:02:44,360 --> 00:02:46,130 Basically, you can print some message. 37 00:02:46,130 --> 00:02:52,700 You can, I don't know, ask the user to specify the file name again and I don't know, exit the program 38 00:02:52,910 --> 00:03:00,770 based on on the application you are going to develop and now we are going to use the L's else is related 39 00:03:00,770 --> 00:03:06,280 to the fact when the returned result from F open was not equal to now. 40 00:03:06,350 --> 00:03:06,800 Right. 41 00:03:07,840 --> 00:03:10,000 So the file was successfully opened. 42 00:03:10,270 --> 00:03:16,790 Let's bring some message, I don't know, the file is opened for writing. 43 00:03:17,410 --> 00:03:18,150 All right. 44 00:03:18,190 --> 00:03:18,640 Right. 45 00:03:19,930 --> 00:03:27,760 And now what we are going to do is basically here once the file has been opened, let's take it under 46 00:03:27,760 --> 00:03:29,050 some curly brackets. 47 00:03:29,560 --> 00:03:30,640 So like this. 48 00:03:31,840 --> 00:03:41,110 We will be able to write some code associated with the file we associated with the file, basically 49 00:03:41,110 --> 00:03:44,110 write some information into this file and so on and so forth. 50 00:03:44,470 --> 00:03:46,960 And the last step, right? 51 00:03:46,960 --> 00:03:49,710 This was the fourth step. 52 00:03:49,720 --> 00:03:50,530 Here it is. 53 00:03:52,260 --> 00:04:03,930 And OK, and basically, let's just classify it here, step four, OK, which is optional, write some 54 00:04:03,930 --> 00:04:08,400 code associated with the final step five F Glos F.P.. 55 00:04:09,480 --> 00:04:10,070 All right. 56 00:04:11,100 --> 00:04:13,380 So what do you say? 57 00:04:13,440 --> 00:04:14,160 Is it clear? 58 00:04:14,190 --> 00:04:19,840 Let's just get it into the LS section so there will be no problems. 59 00:04:21,420 --> 00:04:22,070 Awesome. 60 00:04:22,710 --> 00:04:24,230 So what will happen now? 61 00:04:24,750 --> 00:04:28,590 What will happen now when we will run these programs? 62 00:04:29,430 --> 00:04:34,500 What will happen is basically we can see on the console application these massive message. 63 00:04:34,500 --> 00:04:38,970 The file is open for writing that was done using these print command. 64 00:04:39,900 --> 00:04:47,040 But behind the scenes what has happened is that if you take a look at this project, you will see that 65 00:04:47,790 --> 00:04:55,890 my first file, which is the name of these file, was created inside of this project. 66 00:04:56,340 --> 00:05:00,360 OK, so this is a file that was created inside of these project. 67 00:05:01,450 --> 00:05:07,480 And if you would like to open it up, you can do so, but currently it's an empty file because we did 68 00:05:07,480 --> 00:05:11,180 not put any information to this file. 69 00:05:11,210 --> 00:05:19,450 OK, but one thing I want to show you is that from the program that you've written, you created it 70 00:05:19,450 --> 00:05:20,200 totally. 71 00:05:20,230 --> 00:05:21,890 Let's call it separate file. 72 00:05:22,300 --> 00:05:23,410 Currently it's empty. 73 00:05:23,410 --> 00:05:31,120 But here at step four, where you are going to write some code associated with this file, you will 74 00:05:31,120 --> 00:05:38,270 be able to use various different functions to put some information to these file. 75 00:05:38,560 --> 00:05:40,870 OK, and then the file is not going to be empty. 76 00:05:41,550 --> 00:05:44,220 OK, so I hope that's clear so far. 77 00:05:44,500 --> 00:05:47,710 And if you have any questions, feel free to ask them. 78 00:05:49,300 --> 00:05:56,590 One last thing before we finish this video is that I would like to let you know if you, for example, 79 00:05:56,590 --> 00:06:01,490 would like to specify a different path for your file. 80 00:06:01,510 --> 00:06:11,980 OK, if you would not like to take these file into story, basically under I'm the director of the project 81 00:06:11,980 --> 00:06:14,820 here, but rather you would like to story of this file. 82 00:06:14,890 --> 00:06:16,680 I don't know, on your desktop. 83 00:06:17,080 --> 00:06:23,270 So in this case, you just should specify the specific path that you are interested in. 84 00:06:23,290 --> 00:06:26,680 So in my case, I would like to go with, I don't know, something like this. 85 00:06:26,950 --> 00:06:38,820 See, OK, users, let's go to users Vladi desktop desk desktop and just specify the name. 86 00:06:38,830 --> 00:06:40,900 I don't know my file one doctor. 87 00:06:42,460 --> 00:06:53,170 So this will create a file that its name is my file one that 60 under this basically a specific path 88 00:06:53,350 --> 00:06:54,950 that you've specified. 89 00:06:55,840 --> 00:06:56,470 All right. 90 00:06:56,920 --> 00:07:03,780 So now you know that you can write a file that did not exist, OK? 91 00:07:04,180 --> 00:07:07,920 You created a file that did not exist so far. 92 00:07:08,920 --> 00:07:18,880 And one thing that maybe it's very important also to mention is that what will happen if basically you 93 00:07:18,880 --> 00:07:19,870 had some file? 94 00:07:20,230 --> 00:07:21,340 OK, where is it? 95 00:07:21,730 --> 00:07:23,170 Let me grab this file. 96 00:07:23,170 --> 00:07:24,430 My first file. 97 00:07:25,400 --> 00:07:30,880 Let's say this is some data on the file. 98 00:07:31,180 --> 00:07:34,030 OK, so this file has some information. 99 00:07:34,030 --> 00:07:34,870 We saved it. 100 00:07:35,110 --> 00:07:36,040 Let's close it. 101 00:07:36,640 --> 00:07:39,010 And now we can see that. 102 00:07:39,100 --> 00:07:39,760 Here it is. 103 00:07:39,760 --> 00:07:41,080 Here is our information. 104 00:07:41,980 --> 00:07:49,640 But what will happen if we go back and basically try to run the program right now? 105 00:07:49,810 --> 00:07:51,150 So what will happen? 106 00:07:51,190 --> 00:07:52,210 What do you think? 107 00:07:53,650 --> 00:08:00,940 So in this case, if we would like to run the program, OK, we will see that everything basically seems 108 00:08:00,940 --> 00:08:02,410 to be working just fine. 109 00:08:02,950 --> 00:08:07,330 But the main question here is about the file itself. 110 00:08:07,330 --> 00:08:08,810 So let's take a look at it. 111 00:08:08,830 --> 00:08:10,180 Where is it here? 112 00:08:10,180 --> 00:08:11,980 Is it my first file? 113 00:08:12,220 --> 00:08:13,600 The file is still there. 114 00:08:13,940 --> 00:08:18,810 OK, but you can see that the file is empty once again. 115 00:08:19,630 --> 00:08:29,170 So the thing that has happened is that the operating mode of w of writing works on a simple principle. 116 00:08:29,470 --> 00:08:38,770 It says if the file does not exist, then created and if the file exists, then overwrite it. 117 00:08:39,100 --> 00:08:46,240 So it doesn't care that there was a file with the same name and with some contents, it says, OK, 118 00:08:46,270 --> 00:08:53,290 you want to create a new file and you are expecting that this operation may overwrite it. 119 00:08:54,220 --> 00:09:01,000 There may be times when we would like to append something to the end of an existing file. 120 00:09:01,090 --> 00:09:01,510 Right. 121 00:09:02,000 --> 00:09:04,890 We will see basically additional examples about that. 122 00:09:04,900 --> 00:09:12,310 But this note is very important for you to understand that using this writing operating mode will create 123 00:09:12,310 --> 00:09:21,550 a new file if the file does not exist or it will overwrite a file if these file already exists under 124 00:09:21,550 --> 00:09:22,580 this specific path. 125 00:09:22,580 --> 00:09:24,200 And that you will specify here, OK. 126 00:09:24,220 --> 00:09:31,930 So if you would like to create it under the desktop folder, then make sure that these file does not 127 00:09:31,930 --> 00:09:35,050 exist there, otherwise it will be overwritten. 128 00:09:35,260 --> 00:09:43,420 And any new information that you will specify in step for will be placed under these file overwriting 129 00:09:43,420 --> 00:09:45,910 the previous information that was there. 130 00:09:46,360 --> 00:09:47,710 OK, awesome. 131 00:09:48,700 --> 00:09:49,900 Very good guys. 132 00:09:49,930 --> 00:09:50,810 Very good. 133 00:09:50,830 --> 00:09:53,800 We are going and doing great. 134 00:09:55,050 --> 00:10:05,160 And now just to wrap things up and specify the second operating type of operation, which is reading, 135 00:10:05,580 --> 00:10:07,680 let's go and say something like this. 136 00:10:07,680 --> 00:10:10,740 Let's take this file that we have here. 137 00:10:10,770 --> 00:10:11,070 Right? 138 00:10:11,070 --> 00:10:11,760 Here it is. 139 00:10:12,120 --> 00:10:15,930 Let's go like, hello, we have this message. 140 00:10:15,930 --> 00:10:16,770 Let's close it. 141 00:10:17,280 --> 00:10:22,980 And what I would like to do now is basically to read from these file. 142 00:10:23,010 --> 00:10:30,420 So these program, whenever I will run it, it will basically use the PHP pointer to read information 143 00:10:30,420 --> 00:10:31,470 from these file. 144 00:10:31,950 --> 00:10:39,180 Although in this video, I'm not going to show you different functions that will grab the information 145 00:10:39,180 --> 00:10:42,990 from this file and basically do with it whatever you like. 146 00:10:43,260 --> 00:10:49,980 But basically, I'm just going to show you how this opening process will work behind the scenes and 147 00:10:50,130 --> 00:10:55,890 basically just to let you know that everything was successful so was successful or not successful. 148 00:10:55,920 --> 00:10:56,950 We'll see right now. 149 00:10:56,970 --> 00:11:00,330 So let's go like this. 150 00:11:00,330 --> 00:11:03,290 So we have this file right here, OK? 151 00:11:03,420 --> 00:11:07,880 And we are going to run it and see if the opening process was successful. 152 00:11:08,250 --> 00:11:11,350 So the file is open for writing. 153 00:11:11,530 --> 00:11:13,530 Yeah, but we are going for reading. 154 00:11:13,650 --> 00:11:14,050 Right. 155 00:11:14,070 --> 00:11:15,390 So let's just update it. 156 00:11:16,140 --> 00:11:18,230 So the file is ready for reading. 157 00:11:18,240 --> 00:11:25,110 Let's run it and the file is opened for reading and we can start reading from these file. 158 00:11:25,890 --> 00:11:30,840 But let's try opening some file that does not exist. 159 00:11:31,150 --> 00:11:32,430 OK, for reading. 160 00:11:33,030 --> 00:11:36,840 OK, we will try to open a file that does not exist. 161 00:11:37,260 --> 00:11:42,580 So we can see here under these folder we have like a file, my first file that the extension. 162 00:11:42,960 --> 00:11:46,350 So we can say for sure we don't have like something like this. 163 00:11:46,560 --> 00:11:51,540 I don't know my second file that this file does not exist. 164 00:11:51,540 --> 00:11:51,830 Right. 165 00:11:51,840 --> 00:11:56,160 You can see that it does not exist under these directories. 166 00:11:57,210 --> 00:12:06,110 So if we will try to run now this program, so what we will see that the opening of this file has failed. 167 00:12:06,690 --> 00:12:15,000 So it makes sense, right, that the operating system could not manage to find my second file that under 168 00:12:15,000 --> 00:12:19,890 this project and to open it up simply because it does not exist. 169 00:12:20,910 --> 00:12:23,670 It's very different from the writing operating mode. 170 00:12:23,670 --> 00:12:23,960 Right. 171 00:12:23,970 --> 00:12:27,690 Because when you try to write a file that does not exist, it makes sense. 172 00:12:27,690 --> 00:12:30,930 OK, if it doesn't exist, let's create the file and write it. 173 00:12:31,320 --> 00:12:36,370 But if we want to read from some place in memory specified by the file name. 174 00:12:37,080 --> 00:12:44,010 But this file does not exist, so it makes sense that the file opening will fail. 175 00:12:44,980 --> 00:12:52,000 And in these type of cases, what you would like to do is basically also but that's not going to be 176 00:12:52,000 --> 00:12:52,750 discussed here. 177 00:12:53,680 --> 00:13:01,870 He's to try and understand what was the reason for these fail, whether it was because the child is 178 00:13:01,870 --> 00:13:05,700 not that did not exist or basically something else. 179 00:13:06,310 --> 00:13:12,910 But for now, it's just important for you to know that not every time this operation is going to be 180 00:13:12,910 --> 00:13:13,600 successful. 181 00:13:13,600 --> 00:13:20,650 So it's very important, especially for the first steps that you are taking with working with files 182 00:13:21,280 --> 00:13:27,100 to right this condition and to make sure that the opening process has been successful. 183 00:13:27,100 --> 00:13:34,570 Otherwise, there may be some problems with trying to access different information from an operation 184 00:13:34,780 --> 00:13:37,840 like F Open that was not so successful. 185 00:13:39,490 --> 00:13:41,770 So, yeah, this is it for this video. 186 00:13:41,770 --> 00:13:45,940 I hope you got some information, some useful information from this one. 187 00:13:46,180 --> 00:13:52,750 And in the next videos, we are going to proceed with the material and also talk about common input 188 00:13:52,750 --> 00:13:53,800 and output functions. 189 00:13:54,190 --> 00:13:58,600 And maybe I will also divide them to more smaller videos. 190 00:13:58,780 --> 00:14:00,730 Each video will discuss different function. 191 00:14:00,880 --> 00:14:01,560 I don't know. 192 00:14:01,600 --> 00:14:02,920 Wait till the next video. 193 00:14:03,280 --> 00:14:05,180 Until then, have a great day. 194 00:14:05,230 --> 00:14:06,150 My name is Vlad. 195 00:14:06,310 --> 00:14:07,570 This is Alphatech. 196 00:14:07,570 --> 00:14:12,670 We are eLearning files and we are learning them great. 197 00:14:13,840 --> 00:14:15,940 So until next time, bye bye. 17871

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.