Hey, welcome back. Scott Stanlick, here. We're gonna take a look at file.io in this module. These lessons will cover the old way of doing things, the new way of doing things. We will take a look at creating and manipulating temporary storage, and we'll demonstrate how to write a file finder using depth-first search techniques. In this first lesson, we're gonna compare and contrast the way things have been forever to the way things are now with IO. So if you notice over here, a few things that I just wanna mention. IO's been around since Java 1.0, and it wasn't the greatest IO library. It had some problems. And those problems have since been addressed. I'm using something called java.nio, or the new IO. Since Java 7, you can choose between either one of them. In the NIO, this new library brings the same functionality that we had with java.io, but with massive improvements. And there's also an easy way of migrating effortlessly between the two. The legacy java.io is not recommended for new development, but there are no plans to deprecate it. It's not going anywhere because it's used all over the place. So we're gonna take a look at a couple of types here, one called java.nio.file.Path, which will do everything that file did, and generally in a better way. So let's just jump right in here. So once upon a time, if we wanted to create a file, we would say new File. And then we could turn around and delete the file with file.delete. And maybe it worked, maybe it didn't, but the feedback was lackluster, to be sure. There was poor error handling, few exceptions. The result could be it doesn't exist. You don't have permissions. There were a lot of shortcomings with that API. The new way of doing this is to say Path.of Foo.java. And if you try to use the delete method on the Files class and pass it this path, and the file doesn't exist, you're gonna get a really nice exception. Like for instance, it may throw a NoSuchFileException if it doesn't exist. But there are many other exceptions that this guy may present to you that explain to you full well why it may not have worked. The support between the new IO and the legacy is, as I mentioned earlier, it's effortless. So the old world was I wanna create a new file. You can pass it the parts, the /java folder, the file Foo.java. Same thing goes with Paths.get. Paths is the new way of doing it. If you want to swap between old and new, the file has a toPath, which is the way of making the old look new. And the new has a toFile, which is a way of making the new look old. And so depending upon your context, you may need to use one technique or the other, but you have them both available at any point. There was a way of getting metadata from a file. So that hasn't changed much. It's just slightly different in the way you go about using it. So we'll say File, this is the old world, and we'll say Path, that's the new world. And so we have a file and a path, and the java.io looked like this. These were the methods involved in getting metadata about a file. Is it in a directory? Can I read it, write it? Is it executable, is it hidden? All of those ideas. And using the new API, we use the Files class. The Files class has many methods on it, which we use when we pass the path into those methods, and it'll tell us basically the same things. But these, they're much more robust in the way they were designed. It's newer, and we learned our lessons. So this was how we might have worked with a file using java.io, so a new file. And I'm going to put it here in src/test/java/com/acme/io. I must have a folder somewhere in here like that. I do, com.acme.io. I can ask for a canonical file name. I can ask if it exists or not. And then likewise, I can also convert it to the new world and validate it again. So here we go, Files.exist, file.toPath. So now I take the old one, and I turn it into a path. And this is very similar. I'm creating the same file, and I'm going to ask for its absolute path and whether or not it exists. And likewise, I can convert from the new world back to a file, so I can convert it to legacy and do the same validation again. In the java.io space, the legacy, there was a method called listFiles. If you wanted to get a directory of all the files in a directory, you'd say listFiles, and it would return an array, a file type. The new world's a little bit different. You say Files.newDirectoryStream, and we've already looked at java.util.streams with the filters and maps and translations and all of that good stuff. Files.newDirectoryStream takes your path to source and returns a directory stream called paths here. And in this case, we can say for each element in the stream, we're gonna print it out. So this is just the new way of listing the files that exist in a directory. I appreciate you watching.