You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/ch8_filehandling.ptx
+24-30Lines changed: 24 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -440,7 +440,7 @@ public class CreateFile {
440
440
<title>Deleting Files</title>
441
441
442
442
<p>
443
-
Finally, we will take a look at using Java to delete files. This one is pretty straight-forward and follows the structure used to create files. This time, however, try/catch blocks are not needed for the program to compile. First, the CreateFile class from before will be used to create a file:
443
+
Lastly, we will take a look at using Java to delete a file. This is pretty straight-forward and follows the structure used to create files. Here is the <c>CreateFile</c> class from before that will be used to create a file that we will soon delete:
The next example is Python code that can be used to delete files. This code cannot be run because importing <c>os</c> is not possible with the technologies used to write this book:
This is almost identical to the code within the try block of the CreateFile class we made earlier. The main difference is the use of the <c>delete()</c> method. This method will delete any file with the name provided when creating the myFile object. Similar to the <c>createNewFile()</c> method, it will return <c>true</c> if the file existed and could be deleted, and false if the file could not be deleted.
504
+
Note that this is almost identical to the code within the <c>try</c> block of the <c>CreateFile</c> class that we made earlier. The key difference is the use of the <c>delete()</c> method which will delete the file with the name that was linked to the myFile object. Similar to the <c>createNewFile()</c> method, it will return <c>true</c> if the file exists and can be deleted, and <c>false</c> if the file cannot be deleted.
0 commit comments