YouTube2Text

Java básico 19 - Gestión de archivos en Java - II — Transcript

by JR2B · 6,698 words · 1,264 segments · language en · Watch on YouTube

Full transcript

  1. 0:02Perfect. So,
  2. 0:05uh, let's open our IDE.
  3. 0:12Very good.
  4. 0:14So here we are, right where we left off
  5. 0:16, which was reading the contents of a
  6. 0:18file.
  7. 0:20We saw the process of how we did it, you
  8. 0:22did the homework, and so on.
  9. 0:27So, uh, today we are going to continue
  10. 0:30with, uh, how to copy a file.
  11. 0:33So, I am going to remove everything that
  12. 0:35is here.
  13. 0:39Let's work with a cleaner file. You
  14. 0:41already have all of this in the other
  15. 0:43video just in case
  16. 0:47so that everything remains clear.
  17. 0:51Very good,
  18. 0:56there we have our file that was already
  19. 0:58created from the previous video, the
  20. 1:00file, and we will work on this one.
  21. 1:03Uh, I am going to run the program to see
  22. 1:05that it doesn't have any kind of error.
  23. 1:11It is compiling there.
  24. 1:17Perfect. There it is. File handling in
  25. 1:20Java.
  26. 1:21There is no error. So we are going to
  27. 1:23work with
  28. 1:25uh
  29. 1:28we are going to be working with
  30. 1:33copying
  31. 1:37a file.
  32. 1:39That is what we will be doing now.
  33. 1:43So we, uh, can copy the contents of one
  34. 1:47file to another using one of the classes
  35. 1:50that come when we install the Java
  36. 1:53Development Kit.
  37. 1:56Those classes are called FileInputStream
  38. 2:00and FileOutputStream.
  39. 2:04Using, I'm going to repeat, we are going
  40. 2:07to use the classes, uh, file
  41. 2:11input,
  42. 2:14that one you see on screen,
  43. 2:15FileInputStream.
  44. 2:18And we are going to use the other one
  45. 2:22called file
  46. 2:25output
  47. 2:32file this one right here
  48. 2:38stream.
  49. 2:39Exactly. So, using the FileInputStream
  50. 2:43class, we can read the content of the
  51. 2:47source file.
  52. 2:50Yes, with this class,
  53. 2:54uh, we can read the content of the
  54. 2:57source file and, using the other class,
  55. 3:00the file input, sorry, the file output,
  56. 3:03this machine that we are going to use to
  57. 3:06write our, our other file, that is, the
  58. 3:09copy that we are going to make, we are
  59. 3:12going to use the class file
  60. 3:17OutputStream, this one right here.
  61. 3:20So, with this we read the file.
  62. 3:24Let's enlarge it a bit so you can see it
  63. 3:26better.
  64. 3:28With this, uh, we read the file that we
  65. 3:31want to copy and with the file stream,
  66. 3:34uh, we send it to be written to another
  67. 3:37file.
  68. 3:43So, let's see how we can implement those
  69. 3:46functionalities.
  70. 3:53So,
  71. 3:58the first thing we have to do is
  72. 4:01come over here. We are going to import.
  73. 4:07Notice that I am importing the Java
  74. 4:10package.
  75. 4:13and an asterisk. This asterisk what it
  76. 4:16indicates to the program is, look, load
  77. 4:19all the classes that are inside the java
  78. 4:22package.
  79. 4:25For example, so you can see the
  80. 4:27difference, I can say, "Okay, let's work
  81. 4:30with those two classes."
  82. 4:32So, I can tell it, uh, import Java,
  83. 4:35right?
  84. 4:37IO, I type a dot and it shows me all the
  85. 4:41classes available for IO.
  86. 4:45In this case, io means input output.
  87. 4:50So I can tell it, look, I am going to
  88. 4:51use the file class.
  89. 4:56input stream, this one right here, we
  90. 4:57are going to use it and I select it.
  91. 5:01And I am also going to say that we will
  92. 5:03use
  93. 5:07the dot file output, excuse me, file
  94. 5:10output stream.
  95. 5:13Yes.
  96. 5:15And there we have the two classes
  97. 5:19imported to be able to work with our
  98. 5:21functions that we are going to create.
  99. 5:25If we don't do the imports, then it
  100. 5:27won't work.
  101. 5:30Usually in these advanced editors, when
  102. 5:34we make use of these classes, the editor
  103. 5:37automatically adds these two imports to
  104. 5:41the class, to our project.
  105. 5:46Yes, but if we want to use, let's say,
  106. 5:49all the IO classes, then we would simply
  107. 5:52have to say import java.io
  108. 5:57asterisk and it would load all the
  109. 6:00others, it would load all that are
  110. 6:03contained there.
  111. 6:06Do you see?
  112. 6:09So, uh
  113. 6:13since we have been working with
  114. 6:16different classes to create files, to
  115. 6:18read, uh, and we are also going to
  116. 6:21delete, then the ideal thing would be to
  117. 6:24use io.
  118. 6:25So that it imports all the ones we are
  119. 6:28going to use.
  120. 6:29Well, so you know, we can do it
  121. 6:32individually.
  122. 6:35If we are only going to work with these
  123. 6:37two, we import them, but since we are
  124. 6:39working with file management in all its
  125. 6:41aspects, let's import them all.
  126. 6:44So, I am going to remove this from here
  127. 6:46and I will stick with this.
  128. 6:48That is what the asterisk means and it
  129. 6:51applies to any other import that you may
  130. 6:53have.
  131. 7:18Well,
  132. 7:19so let's work B
  133. 7:52Well, so let's get started.
  134. 8:02So here
  135. 8:06I am going to remove this.
  136. 8:08Let's do it all, remove all of this.
  137. 8:11Yes.
  138. 8:16So,
  139. 8:19the first thing we are going to do is a
  140. 8:21try.
  141. 8:23Everyone already knows what the try is
  142. 8:24used for.
  143. 8:25I explained that in the previous video,
  144. 8:28so I won't emphasize it too much.
  145. 8:32I am going to define a variable of type
  146. 8:34byte.
  147. 8:36Yes,
  148. 8:38this is going to be an array. Notice
  149. 8:40that it is an array of type byte
  150. 8:43and I am going to call it, uh, data and
  151. 8:47this will be equal to a new
  152. 8:53let's put it.
  153. 8:59So we are going to create, uh,
  154. 9:11I will complete that now with the catch
  155. 9:13. It is asking me for a catch to trap.
  156. 9:23We are going to fix that now. So, uh,
  157. 9:28we have a char,
  158. 9:31yes? Let's say this one will be called,
  159. 9:34let's say, uh,
  160. 9:38let's call it x, for example, a variable
  161. 9:40.
  162. 9:41Let's say that this will be equal to new
  163. 9:43, uh, char.
  164. 9:46Let's set it to 100, equal to 100.
  165. 9:52So let's
  166. 9:55define, uh,
  167. 9:58our our reading file,
  168. 10:03file,
  169. 10:06define a file input stream object.
  170. 10:10This object, we're going to call it, uh
  171. 10:11,
  172. 10:18let's call it input file, for example,
  173. 10:22input file.
  174. 10:26And this is going to be equal to a new
  175. 10:28file input
  176. 10:31input stream.
  177. 10:33Yes. And there we are going to place, uh
  178. 10:35,
  179. 10:38a name. Let's name it, uh,
  180. 10:42let's name it new
  181. 10:46new
  182. 10:48new file.
  183. 10:50New file dot txt.
  184. 10:54This goes in quotes.
  185. 10:58That's right.
  186. 11:03Let's continue.
  187. 11:06Uh, let's define the output file now.
  188. 11:10F output stream.
  189. 11:14Let's give a name. To this. We're going
  190. 11:16to we're going to call it
  191. 11:18output file.
  192. 11:21It will be equal to a new file stream.
  193. 11:26Here we are going to place
  194. 11:29the,
  195. 11:31let's call it
  196. 11:35destination file, for example,
  197. 11:40semicolon.
  198. 11:44So, uh,
  199. 11:51we're going to here we're going to
  200. 11:54invoke the file, sorry, we're going to
  201. 11:56invoke the
  202. 11:59the file name, the input file.
  203. 12:05to read read
  204. 12:13to read data or data, sorry, since we
  205. 12:16called it data
  206. 12:20and we're going to tell our output file
  207. 12:25to write here and we're going to pass it
  208. 12:33the data.
  209. 12:34Yes,
  210. 12:37let's put a little sign here.
  211. 12:44Let's put data
  212. 12:48contained in the file
  213. 12:59or say
  214. 13:01uh
  215. 13:06the data contained in the in the file
  216. 13:08have been copied.
  217. 13:10Have been copied.
  218. 13:12Yes,
  219. 13:15it would be
  220. 13:24have been copied. So, then what we must
  221. 13:27proceed to do is close the file.
  222. 13:39Yes, we are going to close the file. Uh
  223. 13:42,
  224. 13:50input file dot
  225. 13:58close. We're going to close it
  226. 14:01and we are also going to close the
  227. 14:04output file
  228. 14:08close. We are going to close it.
  229. 14:14Yes.
  230. 14:18So, uh,
  231. 14:24here we are going to place another
  232. 14:26message
  233. 14:30to this.
  234. 14:35Let's tell it, uh,
  235. 14:40showing data from the destination file,
  236. 14:46for example.
  237. 14:49Yes, we're going to do that now.
  238. 14:58So, what we have to do now is a file
  239. 15:01reader. We already saw this in the last
  240. 15:03class. File reader.
  241. 15:07File reader, we give it a name. FR, will
  242. 15:10be equal to a new, uh, file reader.
  243. 15:15It's a new file reader.
  244. 15:17And we are going to assign it a name.
  245. 15:19The name we already gave it. Ah, this
  246. 15:21was this was the name we gave it.
  247. 15:24Destination file.
  248. 15:29We are going to copy this here.
  249. 15:33That's right.
  250. 15:38So here we are going to do a try too,
  251. 15:41we're going to try tr.
  252. 15:47Yes, we're going to try to to read file
  253. 15:51read. We are going to read that file.
  254. 15:55Yes.
  255. 16:06So, we're going to read it. Here it is
  256. 16:08in the
  257. 16:10we use the X. Remember the definition of
  258. 16:13the X. Here we're going to read then
  259. 16:16here X. Yes.
  260. 16:20and
  261. 16:22we are going to
  262. 16:24print
  263. 16:28the content of X. That's right.
  264. 16:32So we are going to do a catch.
  265. 16:34We are going to catch
  266. 16:37in case an exception is thrown.
  267. 16:39Exception.
  268. 16:41We'll call it E
  269. 16:46and we are going to print, in case an
  270. 16:47error occurs, we are going to
  271. 16:51print the stack trace
  272. 16:54of
  273. 16:59finally we are going to
  274. 17:02close the file we are reading.
  275. 17:06Yes.
  276. 17:16And we still need to handle the
  277. 17:18exception, this exception here, that we
  278. 17:20are working on, this one right here.
  279. 17:24So there we are going to do the same.
  280. 17:26Exception
  281. 17:29e
  282. 17:32and we will print, in case an error
  283. 17:35occurs, we will print the stack trace
  284. 17:39here.
  285. 17:42So
  286. 17:44I think
  287. 17:46that's all we need.
  288. 17:51Yes, nothing else to do. Let's see
  289. 18:05let's check the error it has. Let's see
  290. 18:06, it says this error.
  291. 18:13It is written here. This is char.
  292. 18:17Correct.
  293. 18:19Now it's fine.
  294. 18:23Let's run this program to see what
  295. 18:27it will do.
  296. 18:29Good afternoon.
  297. 18:33Let's see how this program works.
  298. 18:40Let's see.
  299. 18:43Exactly. Notice something,
  300. 18:47it's giving me an error because it says
  301. 18:50new file obviously doesn't exist.
  302. 18:53Right?
  303. 18:55So we have to put here
  304. 18:59the file, a file that exists.
  305. 19:04I suspected this would give me an error
  306. 19:06.
  307. 19:07So, look at what is happening. This is
  308. 19:08giving me an error for the following
  309. 19:09reason.
  310. 19:10I am trying to open the file that I am
  311. 19:13trying to copy and it is called new file
  312. 19:15, but that new file doesn't actually
  313. 19:18exist.
  314. 19:20So, when I run the program, when it
  315. 19:22tries to read this, the error is
  316. 19:24triggered.
  317. 19:27Since that exception is not caught, it
  318. 19:28displays it for me immediately here.
  319. 19:31And notice it tells me the exception
  320. 19:33being triggered is the file not found
  321. 19:35exception, meaning the file not found
  322. 19:37exception, and it tells me the name it
  323. 19:39is not finding.
  324. 19:41So to solve this, what I am going to
  325. 19:43give you is this file here, which we
  326. 19:45created in the previous class, which is
  327. 19:47called archivo from Java dot txt.
  328. 19:51So, here where it says new file, I am
  329. 19:53going to put a filename that I know
  330. 19:56exists.
  331. 19:57Look at it, here it is called archivo
  332. 20:03from
  333. 20:05Java. That was the one we made in the
  334. 20:07other class.
  335. 20:08Okay, so with this we will be able to
  336. 20:11work
  337. 20:14correctly. It will try the input file.
  338. 20:19Since it will find it, the error will
  339. 20:21not occur. Let's see now.
  340. 20:24Let's go back to
  341. 20:27run this. I'm going to clear the console
  342. 20:30and let's run it again.
  343. 20:42Good. So, look, it tells me the file, it
  344. 20:45can't find it. So, where is the problem
  345. 20:48?
  346. 20:48It's that I made a typo, meaning, I
  347. 20:50spelled the name wrong.
  348. 20:52Look right here where it's misspelled.
  349. 20:54Archiv. It was missing something here.
  350. 20:56So,
  351. 20:58archivo.
  352. 21:01Now yes, archivo.
  353. 21:05It's missing the R.
  354. 21:08Archivo
  355. 21:10from Java.
  356. 21:12from quit. Now it is, it's spelled
  357. 21:14correctly.
  358. 21:35Let's see. Now we are running it.
  359. 21:39And now yes, look,
  360. 21:43it read the file called archivo from
  361. 21:45Java TXT and created a new one with the
  362. 21:48data that was contained in archivo from
  363. 21:50Java.
  364. 21:52It created a new file called
  365. 21:54archivodestino.txt and then I sent it to
  366. 21:57display the data it found.
  367. 21:59Look there where it's displaying it.
  368. 22:02In fact, notice that now within the
  369. 22:05project, both files are shown.
  370. 22:08Archivo from Java TXT.
  371. 22:12Look at the content here and the
  372. 22:14destination one here, it copied it again
  373. 22:17.
  374. 22:18Yes.
  375. 22:26Very well, let's close this.
  376. 22:34Any doubts, questions? raising your hand
  377. 22:36.
  378. 22:43This is what we have done.
  379. 22:46We simply defined
  380. 22:50uh
  381. 22:52a byte-type variable called datos.
  382. 22:55It is an array. Then we defined another
  383. 22:57array. What would it read? We named it X
  384. 23:00, in this case a name, uh, and created a
  385. 23:03new char of 100.
  386. 23:05So, then we called
  387. 23:09the file from Java, which is the one we
  388. 23:12had saved, and we defined an output file
  389. 23:15that will be called archivo destino.
  390. 23:21We read the data uh and pass it to datos
  391. 23:26.
  392. 23:28Meaning, the reading we do from the file
  393. 23:30, archivo from Java, we store in datos
  394. 23:33and then output file writes datos.
  395. 23:38Finally, uh
  396. 23:42we show the message that the data from
  397. 23:45the file
  398. 23:48from Java TXT has been stored
  399. 23:53or copied.
  400. 23:55We close both files and then we proceed
  401. 23:57to show the data in the new file that
  402. 24:00was created.
  403. 24:02For that, we create a new file reader
  404. 24:05object, pass it the newly created file,
  405. 24:08and attempt to read it.
  406. 24:15Right, so with that we can
  407. 24:20copy a file that already exists, copy it
  408. 24:22to another.
  409. 24:28So, uh
  410. 24:30we are going to work now on deleting a
  411. 24:33file.
  412. 24:34We already created a new one. Now we
  413. 24:36will see how we can
  414. 24:40delete it.
  415. 24:41Right, so
  416. 25:02I am going to clear all this.
  417. 25:06This time I'm not going to comment it
  418. 25:07out, I'm going to delete it.
  419. 25:10Yes.
  420. 25:11I am going to remove all this that is
  421. 25:12here.
  422. 25:19Yes, there we are back to how we were.
  423. 25:24So, what do we do uh to physically
  424. 25:28delete a file?
  425. 25:31For that, we have to invoke the method
  426. 25:34uh which is the delete method of the
  427. 25:38Java class.
  428. 25:40Let's see how we can implement this.
  429. 25:47For example, I can say the following.
  430. 25:52I can, uh, a file, file object.
  431. 25:55I am going to define an object.
  432. 25:58Let's name it
  433. 26:02file.
  434. 26:06That file will be of type new file.
  435. 26:11Yes?
  436. 26:12So there we have to specify the file
  437. 26:15name.
  438. 26:18And in this case, we are going to delete
  439. 26:20the file we just created. File
  440. 26:26destfile
  441. 26:28dot txt.
  442. 26:33Look at it here. This is the file we are
  443. 26:35going to try to delete. So, uh, I define
  444. 26:38an object called file.
  445. 26:41You can give it any other name you want
  446. 26:43, file, this type is file, and we pass
  447. 26:45it the name of the file we wish to
  448. 26:47delete.
  449. 26:50Then
  450. 26:54we are going to create a variable here
  451. 26:56of type boolean
  452. 27:00and we are going to say here, uh,
  453. 27:04file deleted.
  454. 27:08Meaning, file deleted will be equal
  455. 27:13to
  456. 27:15file, which is the object we just
  457. 27:17created.
  458. 27:18Option to put here
  459. 27:21file.
  460. 27:25File
  461. 27:27dot
  462. 27:30to invoke the method, and we look for
  463. 27:32the delete method. Look at it there.
  464. 27:35The delete method, when it is executed,
  465. 27:40uh, returns a boolean, which means that
  466. 27:43if the operation of deleting the file
  467. 27:45was executed correctly or successfully,
  468. 27:48then it returns a true.
  469. 27:51And that value it returns, I am storing
  470. 27:54it in the boolean variable file deleted
  471. 27:56.
  472. 27:57Yes?
  473. 28:00So here I can put a conditional.
  474. 28:03There are several ways to do this, but I
  475. 28:05am going to do it in the simplest way. I
  476. 28:07am going to say if, I am going to ask a
  477. 28:09question.
  478. 28:12If file deleted
  479. 28:16if it is true.
  480. 28:18Then here I am going to output a message
  481. 28:20, a small message that says
  482. 28:23uh
  483. 28:26the file has been deleted
  484. 28:30successfully.
  485. 28:34It has been deleted. All right.
  486. 28:36Been deleted.
  487. 28:41If we want, we can add an else.
  488. 28:43Otherwise,
  489. 28:46we can say
  490. 28:54the file could not be deleted,
  491. 29:02so to speak.
  492. 29:04Yes.
  493. 29:12And that's it. That is all we have to do
  494. 29:14. Notice, when we run this process, this
  495. 29:17program, it will simply do is, uh,
  496. 29:20create an object of type file, and to
  497. 29:23that file, the physical file we have
  498. 29:26created, destfile.txt, will be assigned
  499. 29:30, and it will try to delete it.
  500. 29:33If it deletes it, that method will
  501. 29:35return a boolean indicating true if it
  502. 29:37deleted it, or false if it did not
  503. 29:38succeed.
  504. 29:40Then that value it returns is stored in
  505. 29:42file deleted.
  506. 29:44Finally, I send to display on the screen
  507. 29:46whether the file was deleted or not.
  508. 29:50Let's run this and see how it goes.
  509. 29:58And there it is. Look, the file has been
  510. 30:01deleted. If you notice, it's already
  511. 30:06the file we had, which was called
  512. 30:08destination file, is no longer in the
  513. 30:10folder, which means
  514. 30:14that the procedure was carried out
  515. 30:16correctly. It has deleted the file, um,
  516. 30:22destination.txt.
  517. 30:30Perhaps you could place, um,
  518. 30:37a question, um, asking if you really
  519. 30:40want to delete the file,
  520. 30:44and depending on what the user answers—
  521. 30:46this is just to talk, for example—you
  522. 30:47would have to capture input via the
  523. 30:49console asking if they wish to delete
  524. 30:50the file.
  525. 30:52If they answer yes, then proceed to
  526. 30:53execute the deletion method.
  527. 30:56If they answer no, then you could output
  528. 30:59a comment saying that the process of
  529. 31:01deleting the file has been canceled.
  530. 31:14So, um,
  531. 31:19it is quite straightforward, there is no
  532. 31:21need to overcomplicate this.
  533. 31:23So, let's see now, um,
  534. 31:29permissions in Java.
  535. 31:34What do we mean here by permissions in
  536. 31:37Java?
  537. 31:40We can verify file permissions using, um
  538. 31:44, different methods present in the Java
  539. 31:48file classes.
  540. 31:52What I am going to show you now is an
  541. 31:54example, um,
  542. 31:57to verify if the file we are trying, um
  543. 32:01, to use has read, write, and execute
  544. 32:05permissions.
  545. 32:08Let's see how we do that.
  546. 32:16So, I am going to remove all of this
  547. 32:21here.
  548. 32:23I will leave the label "file handling."
  549. 32:25I am going to remove all of this.
  550. 32:28Well, we can leave this one for the new
  551. 32:30file. We are going to use—we are not
  552. 32:32going to use, um, destination file
  553. 32:35because it no longer exists; we deleted
  554. 32:37it. Let's give it the other name since
  555. 32:40we have a file there that is still there
  556. 32:42. File
  557. 32:48file
  558. 32:50from.
  559. 32:55So now we can remove this because we are
  560. 32:57not going to delete it.
  561. 33:02Let's remove this.
  562. 33:04So, um,
  563. 33:08let's place a few comments here.
  564. 33:15Let's put, um,
  565. 33:21permissions
  566. 33:23available.
  567. 33:27Permissions available for
  568. 33:33here we are going to place
  569. 33:37um, file, right? Let's put file.
  570. 33:43Let's look for a method that displays
  571. 33:45the name for me.
  572. 33:47Let's see if we have, um, I think I have
  573. 33:50"get name" to get the file name.
  574. 33:54Let's test it immediately.
  575. 33:58If this is working. Let's run the
  576. 34:00program.
  577. 34:05Indeed,
  578. 34:10look at the file here, permissions
  579. 34:13available for file TXT.
  580. 34:17In fact, I am going to place it, um,
  581. 34:21let's put it better like this, so it
  582. 34:22looks a little better.
  583. 34:24Let's remove this from here.
  584. 34:28Yes.
  585. 34:31And below we are going to print another
  586. 34:34label. Yes.
  587. 34:37And here we are going to place "
  588. 34:38permissions available for"
  589. 34:45the file.
  590. 34:48And now we are going to place
  591. 34:54the method.
  592. 34:57What this method does is return the name
  593. 34:59.
  594. 35:00We are going to place
  595. 35:03some small—we are going to create a kind
  596. 35:05of
  597. 35:07of output.
  598. 35:09Yes, let's copy this here as well to
  599. 35:12give it a little bit of formatting, so
  600. 35:15to speak.
  601. 35:24Yes, I think that
  602. 35:26is fine.
  603. 35:31Very well.
  604. 35:33Let's test this. Let's test how the code
  605. 35:36is going.
  606. 35:40Yes, look, we created the
  607. 35:44effect I wanted.
  608. 35:47It needs to be separated a bit. Let's
  609. 35:48adjust it here.
  610. 35:51Let's add a space so it stays
  611. 35:56let's put some arrows here. Like this.
  612. 36:00Let's run this again.
  613. 36:06Perfect. Much better. There is the name
  614. 36:08. It's displayed now.
  615. 36:11If we wanted, we could center this a bit
  616. 36:13more, I don't know, to
  617. 36:17give it a bit of shape.
  618. 36:20handling.
  619. 36:23Let's see.
  620. 36:29Oh yes, much better.
  621. 36:33More.
  622. 36:39Perfect.
  623. 36:40So, we already have our sign, file
  624. 36:41handling, the permissions available for
  625. 36:43the sign.
  626. 36:45So, let's see how we can display on the
  627. 36:47screen what permission the file has.
  628. 36:50So,
  629. 36:53we are simply going to display a few
  630. 36:55signs.
  631. 36:56Here we are going to write, for example
  632. 36:58,
  633. 37:02let's check for execution.
  634. 37:11execution. If it has execution
  635. 37:13permission.
  636. 37:17Yes.
  637. 37:35That's right. Execution permission.
  638. 37:38And there we will display it.
  639. 37:44Let's tell the file to tell me, let's
  640. 37:47look for the method that allows me to
  641. 37:49show if it has permission.
  642. 37:52Let's look for a method called execute.
  643. 37:56Look at it there.
  644. 37:58Can execute. Look at it there. If it can
  645. 38:00be executed. Can execute.
  646. 38:03It is a method that returns a boolean.
  647. 38:06Yes,
  648. 38:09we already have the first one.
  649. 38:12Let's copy this same thing here.
  650. 38:16And now we will call this one reading.
  651. 38:19We will make it readable, so to speak.
  652. 38:24Reading. Let's put reading. I think it's
  653. 38:26better understood. Reading.
  654. 38:29Put execution permission.
  655. 38:32I think it would look better as reading
  656. 38:33.
  657. 38:34Let's see if it has read permission.
  658. 38:37How could we see that? We simply change
  659. 38:39the method instead of can execute.
  660. 38:43Let's look for the one that allows me to
  661. 38:44show that. So we are going to say can
  662. 38:47can can can can read. Look at it. Here
  663. 38:51I select it.
  664. 38:55What else could we apply there?
  665. 38:58Let's see if we have write permission.
  666. 39:01It is the same process.
  667. 39:03System.
  668. 39:04Println.
  669. 39:07Yes.
  670. 39:09Tell it there write.
  671. 39:13Write.
  672. 39:15That's right.
  673. 39:18We have it.
  674. 39:22And the only thing we have to do now is
  675. 39:24invoke.
  676. 39:31That's right here file dot
  677. 39:37we are looking for if we can write. So
  678. 39:40it would be can write. Look at it here.
  679. 39:47And there it is.
  680. 39:48So, this should display on the screen.
  681. 39:53Let's draw a line underneath so that
  682. 40:02here we are going to change it, we are
  683. 40:04going to put
  684. 40:07shape.
  685. 40:14Let's see how this looks.
  686. 40:21We are running it, compiling to see if
  687. 40:22there are any errors.
  688. 40:24And look,
  689. 40:27it tells me that I have execute, read,
  690. 40:31and write permissions.
  691. 40:35Let's see if I can change
  692. 40:38the permissions. Let's see.
  693. 40:43I would have to go to the folder.
  694. 40:50Let's see.
  695. 40:58C: users user. Okay. Let's see. I'm
  696. 41:01going to go to the folder.
  697. 41:09Just a second, I'm going to try to
  698. 41:11change
  699. 41:14users user,
  700. 41:17IntelliJ Projects,
  701. 41:24Java Basic, the file from Java. I'm
  702. 41:28going to try to change the permission.
  703. 41:31I'm going to properties. Let's see.
  704. 41:35Okay. And I'm going to set it here to be
  705. 41:39read-only.
  706. 41:44I'm going to click save.
  707. 41:46Okay.
  708. 41:48Now I'm going to run my program again to
  709. 41:50see what it says.
  710. 41:55Let's run it.
  711. 41:59Look,
  712. 42:01now the file says execute. true for read
  713. 42:05, true for write, false. Which means
  714. 42:10that I cannot modify this file because
  715. 42:13it is false.
  716. 42:16I cannot write to it because, through
  717. 42:18the operating system, I have told that
  718. 42:21file that it is read-only, which is why
  719. 42:23I cannot modify it.
  720. 42:27So, if I go back to the folder, select
  721. 42:30the file again, and right-click,
  722. 42:33properties,
  723. 42:35you can't see it.
  724. 42:37That's correct, student, you can't see
  725. 42:39it.
  726. 42:39But you are supposed to know at this
  727. 42:43stage of the game how to set a file's
  728. 42:47properties.
  729. 42:49This is operating systems. I mean, I
  730. 42:51just go to a folder, it's as simple as
  731. 42:53that. That's why I haven't shared it,
  732. 42:56but well, I'm going to
  733. 43:01It doesn't hurt. I'm going to stop this
  734. 43:03here.
  735. 43:04I'm going to share my window here.
  736. 43:09Now you can see it, student. Yes,
  737. 43:15you can see it.
  738. 43:16Yes, it's visible.
  739. 43:18Perfect. So, look, there is the file.
  740. 43:22So, I select it, right-click, properties
  741. 43:25.
  742. 43:26Do you see it?
  743. 43:28It shows me the file properties. Notice
  744. 43:31where it says attributes read-only,
  745. 43:33hidden.
  746. 43:34There are others here that you can
  747. 43:36define.
  748. 43:38In this case, I'm only going to tell it
  749. 43:39what it will be.
  750. 43:42I uncheck the box that says read-only so
  751. 43:44that it can be overwritten.
  752. 43:46When it is checked, it means that it is
  753. 43:49read-only, that I cannot modify it.
  754. 43:52So, I uncheck it.
  755. 43:54Now it will be available for read and
  756. 43:58write.
  757. 44:01If we want to apply more, we can go to
  758. 44:02advanced
  759. 44:04and there we see other options.
  760. 44:07But for the example we are doing, if I
  761. 44:10click apply,
  762. 44:13right? So I'm going to stop sharing here
  763. 44:16. I'm going to share the project again.
  764. 44:20Yes,
  765. 44:23you are seeing the code again there. The
  766. 44:25file is already there. I removed the
  767. 44:27read-only condition.
  768. 44:30If I run the program, then for writing,
  769. 44:32notice how it tells me now.
  770. 44:35Writable true, meaning that I can modify
  771. 44:40that file.
  772. 44:44and I put it back on.
  773. 44:55If I go back and set my file
  774. 45:00in properties to be read-only, meaning I
  775. 45:02cannot modify it.
  776. 45:08I'll stop this here. Here I share the
  777. 45:11code again.
  778. 45:13I have put the code back to read-only,
  779. 45:15the read-only attribute.
  780. 45:18If I run the program now, look at what
  781. 45:20it will tell me at the end.
  782. 45:23It says false because I set it to be
  783. 45:26read-only.
  784. 45:28Good,
  785. 45:31I think this is quite clear, quite easy
  786. 45:33to apply.
  787. 45:36I'm going to set this back to how it was
  788. 45:37.
  789. 45:39Okay, ready.
  790. 45:43So, uh, let's see now finally
  791. 45:51how we can list files in the directory,
  792. 45:54how we can show all the files we have
  793. 45:57from a Java program.
  794. 46:03Uh, with this example I'm going to show
  795. 46:06you now, we are going to create a new
  796. 46:08directory using the MKDIR method.
  797. 46:11That is an operating system command, and
  798. 46:14we are going to create some new files
  799. 46:17inside that directory using the class
  800. 46:20you already know called createNewFile.
  801. 46:27and then we will be able to list the
  802. 46:29file contents using the list method.
  803. 46:33So let's
  804. 46:37work with that.
  805. 46:43For now, I'm going to need to take the
  806. 46:50address of the folder where I want to
  807. 46:52work. I already have it copied here.
  808. 46:56So let's get to work.
  809. 47:04So, uh
  810. 47:08we already have this execution ready.
  811. 47:10This I'm going to
  812. 47:13I'm going to remove.
  813. 47:18Remember, this will be recorded, you
  814. 47:20will be able to watch it again calmly
  815. 47:22and do all these steps again.
  816. 47:26So, uh, I'm going to place the path here
  817. 47:29in a comment so you can see where it is
  818. 47:31.
  819. 47:32That is the path where we are working.
  820. 47:35So, uh, let's see how we do this.
  821. 47:51Well, so let's go.
  822. 47:53The first thing I'm going to do is
  823. 47:56create a file, a new file.
  824. 47:58You already know what this command means
  825. 48:00. I'm going to give it a name so it
  826. 48:03looks easier to understand. An object
  827. 48:07called F of type file. I could have
  828. 48:10given it, uh, any other name. For
  829. 48:13example, let's call it new file, for
  830. 48:16instance.
  831. 48:19Yes, new file.
  832. 48:22The object. New file.
  833. 48:26Yes.
  834. 48:27And new file.
  835. 48:29Will be equal. Please, mute your
  836. 48:31microphones.
  837. 48:33It's just like a new file.
  838. 48:38F.
  839. 48:44In fact, let's call it,
  840. 48:48yes, let's leave it as file.
  841. 48:55Let's give that new file a name, let's
  842. 48:57call it
  843. 48:59uh
  844. 49:02directory, for example.
  845. 49:11No, sorry, I'm doing something wrong.
  846. 49:19Well, yes, we can do it that way. New
  847. 49:20file. Let's call it, uh, directory.
  848. 49:28Directory
  849. 49:33what we
  850. 49:37are going to do is invoke that on the
  851. 49:39file called new file.
  852. 49:45Notice, we have assigned this name to
  853. 49:48the new file object.
  854. 49:52So, what we are going to do is create an
  855. 49:54if,
  856. 50:01let's put an else as well
  857. 50:04and here we will execute this. We are
  858. 50:06going to say that if
  859. 50:09new file dot and we are going to execute
  860. 50:11the command that allows me to create a
  861. 50:13directory called MKD.
  862. 50:16Look at it here.
  863. 50:20MKS.
  864. 50:22If this executes correctly, it returns a
  865. 50:25boolean, and since I'm asking if the new
  866. 50:28directory MKDIR method is true, it will
  867. 50:31indicate that a new directory has been
  868. 50:35created.
  869. 50:36We are executing this method that allows
  870. 50:39me to create a directory.
  871. 50:41Here I will place a little message.
  872. 50:46It says
  873. 50:48the directory
  874. 50:56directory has been created.
  875. 51:02Otherwise,
  876. 51:05let's copy this same thing. Practically
  877. 51:07the only thing it will say here
  878. 51:11I'll edit it here to
  879. 51:14let's do it like this.
  880. 51:17We will say, the directory, uh, could
  881. 51:20not be created,
  882. 51:24could not be created,
  883. 51:29be created.
  884. 51:32That's right. The directory could not be
  885. 51:34created.
  886. 51:41I can put this all in uppercase, uh,
  887. 51:42there's no problem with that.
  888. 51:45I'm just giving it a kind of style, you
  889. 51:47know,
  890. 51:55has been created. Then, otherwise, the
  891. 51:57file was not created.
  892. 52:03So
  893. 52:08we
  894. 52:11are going to
  895. 52:25In fact, let's test this to see if it
  896. 52:27works.
  897. 52:30I'm going to run it to see if it creates
  898. 52:32the directory for me. Let's see.
  899. 52:34I'm going to run the program.
  900. 52:42It's compiling.
  901. 52:45And notice the message it gives me.
  902. 52:47The directory has been created.
  903. 52:51If you look at the project, a new folder
  904. 52:54appears called directory.
  905. 52:56Look at it here.
  906. 52:58Do you see it? We have created
  907. 53:01the directory, the command created the
  908. 53:03directory inside the folder for me.
  909. 53:06If I, uh, have the share and I share,
  910. 53:12it seems I closed the folder.
  911. 53:14It's here,
  912. 53:17sorry. Here, where is it? Now I got lost
  913. 53:20.
  914. 53:22Share.
  915. 53:26Here it goes, basic. Share.
  916. 53:29You can see, look at the folder we
  917. 53:30created. Look at it there. We just
  918. 53:32created it right now. Look at it there
  919. 53:34with the MKD command.
  920. 53:37We already have the folder created.
  921. 53:40I have the path where it is. Look here,
  922. 53:42that is the path. I copied that and put
  923. 53:45it in a comment. So what we are going to
  924. 53:48do is send it to save inside that folder
  925. 53:50that says directory. We are going to
  926. 53:52save a few files.
  927. 53:53If I enter the folder, you will see that
  928. 53:55it is empty. This folder is empty.
  929. 53:59So, inside that folder we are going to
  930. 54:01place, uh,
  931. 54:05the new files. I am going to copy this
  932. 54:07path,
  933. 54:10I am going to stop sharing. I will share
  934. 54:13my code again and we are going to do it
  935. 54:17.
  936. 54:19Yes, we are going to do it.
  937. 54:30We are going to create a stream.
  938. 54:35We create a stream.
  939. 54:39We are going to say, uh,
  940. 54:42file path.
  941. 54:45Yes, file path will be equal.
  942. 54:49And there I am going to copy
  943. 54:52uh the path.
  944. 54:55Yes.
  945. 54:57And I am going to pass it
  946. 55:00the new name I am going to create. I am
  947. 55:02going to name it, for example,
  948. 55:09file
  949. 55:1201,
  950. 55:16file 01
  951. 55:21dot txt.
  952. 55:25Yes,
  953. 55:27let's create another one of these. I am
  954. 55:30going to copy this.
  955. 55:34This is showing me an error.
  956. 55:37Obviously, the parenthesis does not go
  957. 55:38there.
  958. 55:40And here I am going to copy another one
  959. 55:42. Let's go to file path.
  960. 55:46File path. Let's put 01 on it.
  961. 55:51And to this one we will put file path 02
  962. 55:53.
  963. 55:55A name. And here we will put another
  964. 55:57file name.
  965. 55:5802.
  966. 56:00This does not go.
  967. 56:03So,
  968. 56:06simply
  969. 56:10we are going to define now
  970. 56:15my two files.
  971. 56:19We already know how to do this. I define
  972. 56:21an object of type file, let's call it,
  973. 56:25uh,
  974. 56:27file 01
  975. 56:31is equal to a new, a new file.
  976. 56:36And that new file, what are we going to
  977. 56:38pass to it?
  978. 56:40Well, we are going to pass it the path
  979. 56:41we just created. What is the path?
  980. 56:44File path 01.
  981. 56:49We will do the same with the next one.
  982. 56:51We create an object of type file and
  983. 56:53assign a name. File 02 will be equal to
  984. 56:57a new file object.
  985. 57:02New file object.
  986. 57:06And what path are we going to pass it?
  987. 57:07We are going to pass it this file that
  988. 57:09is here.
  989. 57:15is.
  990. 57:19So, if all this works, it should have
  991. 57:22created my two files.
  992. 57:26Let's execute the program.
  993. 57:28Remember, the folder is empty.
  994. 57:32Let's execute the program to see what it
  995. 57:34shows me.
  996. 57:36I am going to click run.
  997. 57:41Let's wait.
  998. 57:44Perfect.
  999. 57:49It is showing the file. It could not, uh
  1000. 57:52, it could not be created.
  1001. 57:55Sorry.
  1002. 57:58Let's see. The directory could not be
  1003. 58:00created.
  1004. 58:05Obviously, do you know why that is
  1005. 58:07happening? because we already created
  1006. 58:09the directory,
  1007. 58:12but let's, let me enter the directory,
  1008. 58:14let me see.
  1009. 58:15Perfect.
  1010. 58:18What I'm going to do is delete the
  1011. 58:20directory because it's telling me it
  1012. 58:22couldn't be created since the directory
  1013. 58:24already existed.
  1014. 58:27So, what I'm going to do is delete the
  1015. 58:29directory folder.
  1016. 58:31I'm, I'm inside even though you can't
  1017. 58:33see it.
  1018. 58:34I'm going to delete the directory.
  1019. 58:37I just deleted it.
  1020. 58:43Yes. Notice how now in the
  1021. 58:47in the project the directory folder no
  1022. 58:49longer appears. Yes.
  1023. 58:53So I'm going to run my program again.
  1024. 58:56This can also be validated. First, ask
  1025. 58:58if the directory exists, and if it
  1026. 59:01exists, then, uh, I would cancel the
  1027. 59:04creation. But in this case, we'll keep
  1028. 59:06it as is.
  1029. 59:07I simply deleted the folder and I'm
  1030. 59:10going to try running the program again.
  1031. 59:15Let's see. Now I'm going to clear the
  1032. 59:19console here.
  1033. 59:21Let's run the program again. Let's see
  1034. 59:23what happens.
  1035. 59:25Notice now how it tells me the directory
  1036. 59:28has been created.
  1037. 59:30If you look at the project, the folder
  1038. 59:34has been created again.
  1039. 59:42That's right.
  1040. 59:44And if I go to the
  1041. 59:49directory folder,
  1042. 59:54the folder is empty.
  1043. 59:56Let's see. Uh,
  1044. 1:00:02it didn't create the files for me. Let's
  1045. 1:00:05see why.
  1046. 1:00:19I think it has to do with
  1047. 1:00:22with the specified path.
  1048. 1:00:26I'm going to change this. I'm going to
  1049. 1:00:28change, add the slash.
  1050. 1:00:30I'm going to change this. Let's see.
  1051. 1:00:36Yes, I think this.
  1052. 1:00:47Let's see.
  1053. 1:01:29Actually, I think it was fine. It didn't
  1054. 1:01:32save the files because we are missing
  1055. 1:01:33something. It's not the path. I'm going
  1056. 1:01:35to put this back the way it was.
  1057. 1:01:39Now I'm going to, I'm going to explain
  1058. 1:01:41why it didn't save the files, and it's
  1059. 1:01:42obvious.
  1060. 1:01:45Fine, I'm simply reverting the path to
  1061. 1:01:46how it was. I thought it was a problem
  1062. 1:01:49with the path, but let's see if I'm
  1063. 1:01:51wrong.
  1064. 1:01:53Okay, there it is as it was before.
  1065. 1:01:55What are we missing? It's that I created
  1066. 1:01:58the files, but I'm not telling it to
  1067. 1:01:59save them.
  1068. 1:02:02Is that understood?
  1069. 1:02:04So here I have to tell it,
  1070. 1:02:10I have to tell it file 01
  1071. 1:02:15create file. That was the error, why it
  1072. 1:02:18wasn't creating it.
  1073. 1:02:20We create everything, but I have to give
  1074. 1:02:22it the command to create the file.
  1075. 1:02:25And I have to do the same with file 02.
  1076. 1:02:28Create file.
  1077. 1:02:32Now it should work.
  1078. 1:02:33Obviously, I have to delete this folder
  1079. 1:02:35again, this directory folder you see on
  1080. 1:02:37the screen. I'm going to delete it.
  1081. 1:02:40Yes, I'm going to go to the folder.
  1082. 1:02:45Yes, and I'm going
  1083. 1:02:47to remove it.
  1084. 1:02:52I've deleted the folder.
  1085. 1:02:55Notice how it updates the
  1086. 1:02:58uh folder in the basic Java project; the
  1087. 1:03:00directory folder no longer appears.
  1088. 1:03:03So, let's proceed to run everything
  1089. 1:03:05again.
  1090. 1:03:07If everything is correct, the directory
  1091. 1:03:09called "directorio" should be created,
  1092. 1:03:12and it should save or create two files
  1093. 1:03:14inside that directory.
  1094. 1:03:16Let's run the program. Let me clear this
  1095. 1:03:19little console and let's execute the
  1096. 1:03:22program. Let's see how it goes.
  1097. 1:03:26There it is compiling.
  1098. 1:03:32The directory has been generated. It was
  1099. 1:03:34created correctly.
  1100. 1:03:36I'm going to try opening my folder here
  1101. 1:03:37.
  1102. 1:03:39And there it is. Look at it.
  1103. 1:03:42Inside the directory folder, archivo
  1104. 1:03:4501.txt and archivo 02.txt have been
  1105. 1:03:48created.
  1106. 1:03:52Quite easy.
  1107. 1:03:56Yes, we saw, we already saw how we can,
  1108. 1:03:59uh, create directories with Java.
  1109. 1:04:03Inside a directory, how we can, uh, show
  1110. 1:04:06, uh, sorry, how we can create files
  1111. 1:04:08inside a folder by setting the path.
  1112. 1:04:11Look at the path.
  1113. 1:04:12Perhaps your path when you do it will be
  1114. 1:04:15different from mine.
  1115. 1:04:17Yes, but the important thing is that you
  1116. 1:04:20understand how it works.
  1117. 1:04:23I defined a path, there it is, along
  1118. 1:04:25with the file names, and then I create a
  1119. 1:04:27file-type object called archivo01 and I
  1120. 1:04:30tell it to create, I define an object,
  1121. 1:04:32sorry, I am defining the objects here.
  1122. 1:04:37Let's put it here so you don't get
  1123. 1:04:39confused.
  1124. 1:04:41Uh, here we are going to call them, uh,
  1125. 1:04:44objects.
  1126. 1:04:47Objects, uh, created.
  1127. 1:04:50Or the instances.
  1128. 1:04:55Instances.
  1129. 1:04:57Of objects, for example.
  1130. 1:04:59We created the two instances there; the
  1131. 1:05:01two objects are already created.
  1132. 1:05:03So, these two objects already have the
  1133. 1:05:06paths, uh, inside them. Please mute your
  1134. 1:05:08microphone.
  1135. 1:05:10So, then with the two objects, with
  1136. 1:05:12their paths, uh, set, I tell them to
  1137. 1:05:15create the file here. Create new file.
  1138. 1:05:17Create new file.
  1139. 1:05:27Well, then finally let's see now how, uh
  1140. 1:05:30,
  1141. 1:05:35how we can list the files. That is the
  1142. 1:05:37only thing we are missing. Right there.
  1143. 1:05:40Uh,
  1144. 1:05:44I am going to make, I am going to print
  1145. 1:05:46a small sign.
  1146. 1:05:49To this little sign we are going to put
  1147. 1:05:50, uh,
  1148. 1:05:53of files.
  1149. 1:06:01In the directory.
  1150. 1:06:07All in the directory.
  1151. 1:06:12We can do the same thing I did a moment
  1152. 1:06:14ago.
  1153. 1:06:15Yes, I can go up here. Well, I actually
  1154. 1:06:18deleted it.
  1155. 1:06:20Well, here I can
  1156. 1:06:24print
  1157. 1:06:27a little sign.
  1158. 1:06:30You already know what I am doing.
  1159. 1:06:35Put it here.
  1160. 1:06:38So, here we are going to
  1161. 1:06:42in the directory we are going to put
  1162. 1:06:47directory name directory.
  1163. 1:07:00So, which one is the one that contains
  1164. 1:07:01the name?
  1165. 1:07:02Here, new file.
  1166. 1:07:05There I am going to put new file.
  1167. 1:07:09Name so that it gives me the name.
  1168. 1:07:12Yes, this should work.
  1169. 1:07:15This,
  1170. 1:07:18okay.
  1171. 1:07:24Besides, we already displayed the sign.
  1172. 1:07:27So we are going to define an str
  1173. 1:07:30variable.
  1174. 1:07:32This is going to be an array.
  1175. 1:07:36If you saw the video on arrays, you
  1176. 1:07:37should understand this as well.
  1177. 1:07:39Files, let's name it files here, uh,
  1178. 1:07:42files
  1179. 1:07:46found, for example. Found
  1180. 1:07:51is going to be equal
  1181. 1:07:56to
  1182. 1:08:00what is it going to be equal to. Let's
  1183. 1:08:02see.
  1184. 1:08:13Yes, equal to
  1185. 1:08:18new file dot
  1186. 1:08:22list. That is a method.
  1187. 1:08:25List. If it lets me type it right. List
  1188. 1:08:28.
  1189. 1:08:28There it is.
  1190. 1:08:30That
  1191. 1:08:32method, what it does is it returns, look
  1192. 1:08:35, it returns a string array with the
  1193. 1:08:37files, with the file names.
  1194. 1:08:40That's why this method, what it returns
  1195. 1:08:43, I save it in an array, and since it
  1196. 1:08:46returns a string array, I am storing it
  1197. 1:08:49in a string array called files found.
  1198. 1:08:53So, what is the only thing we have to do
  1199. 1:08:55?
  1200. 1:08:57It's simply, as you already know, with a
  1201. 1:08:59for or for each, we could say, I can say
  1202. 1:09:02int i
  1203. 1:09:06equal to zero with the condition while i
  1204. 1:09:10is less than what?
  1205. 1:09:13Than files found and we invoke a method
  1206. 1:09:18, the length method, length. There it is
  1207. 1:09:22.
  1208. 1:09:24The other is we increment our counter,
  1209. 1:09:28we open a code block, and simply what we
  1210. 1:09:32have to do is print, as easy as that,
  1211. 1:09:36print what
  1212. 1:09:41a file, I can add a label if I want,
  1213. 1:09:44name
  1214. 1:09:47file.
  1215. 1:09:50Yes. And to that I am going to
  1216. 1:09:51concatenate what?
  1217. 1:09:54The iteration I am doing, files found
  1218. 1:09:59and I add the index, and this should
  1219. 1:10:03work.
  1220. 1:10:07Let's see, obviously I am going to have
  1221. 1:10:09to delete everything, I am going to have
  1222. 1:10:12to delete the directory so the process
  1223. 1:10:14runs again.
  1224. 1:10:16So, I'm going to go there, select the
  1225. 1:10:20directory, delete it.
  1226. 1:10:24I already deleted it.
  1227. 1:10:26If you notice, the folder no longer
  1228. 1:10:29appears in my project, it's gone.
  1229. 1:10:33Let's run it. I'm going to clear the
  1230. 1:10:35console.
  1231. 1:10:40Well, that's fine. That will clear when
  1232. 1:10:45when I execute the program.
  1233. 1:10:47So, let's run the program again to see
  1234. 1:10:50what happens.
  1235. 1:10:52It is compiling, cleaning. Let's see.
  1236. 1:10:56And there it is. Look at it.
  1237. 1:10:59If we look at the project, the directory
  1238. 1:11:02folder is created.
  1239. 1:11:04If I open the directory, the two files
  1240. 1:11:08we just created are shown.
  1241. 1:11:12Then, from the program, I list the files
  1242. 1:11:14that the directory contains.
  1243. 1:11:17Look at it there. List of files in the
  1244. 1:11:19directory. Directory name. Look at the
  1245. 1:11:22name there. This comes from a method and
  1246. 1:11:25then with a for loop I display the file
  1247. 1:11:28names. Look, file 01 and file 02.
  1248. 1:11:33With this we complete, uh
  1249. 1:11:37file handling in Java.
  1250. 1:11:43All that remains now is for me to
  1251. 1:11:45provide you with a comprehensive
  1252. 1:11:47practice exercise so you can work
  1253. 1:11:49through all the methods we have covered
  1254. 1:11:52in these last two classes.
  1255. 1:11:55Both videos are available there for you
  1256. 1:11:57to consult again.
  1257. 1:12:00So, I will prepare the practice, and by
  1258. 1:12:03using everything we have learned in this
  1259. 1:12:06class along with the previous video's
  1260. 1:12:09class, you will be able to complete it
  1261. 1:12:12without any issues.
  1262. 1:12:16For your attention,
  1263. 1:12:18thank you very much.
  1264. 1:12:22Yes.

About this transcript

This page contains the full transcript of Java básico 19 - Gestión de archivos en Java - II by JR2B, generated from the public captions YouTube serves with the video. The transcript has 6,698 words across 1,264 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.