 Hey everybody, it's Brian. Today we're going to be discussing the file class. First thing we want to do is import the Java.io package. If you have no idea what packages are, you should watch my 8th Java tutorial where we talk about packages and inheritance. Alright, moving right along, we're going to just type file. And I'm going to actually just back up here and show you how to get a list of drives. So we'll type up for each file, mDrive, and file. We'll call it static implementation of list roots. System out.printline. Excuse me. And what we'll do when we run this is we will see a bunch of drives. Now I'm on a Windows system, so of course I've got a bunch of hard drives. Probably more than the average user because I have a lot of hard drives. If you're on a Linux system, you probably just see the typical root slash, same with a Mac. Now let's back up here. That's how you get a list of all the hard drives. I'm just going to get a reference to my C drive here. So we'll say file, mDrive, equal new, file, c, whack, whack. Now that may look a little funny, but the reason why you do two slashes instead of one is because if you just do the one, Java sees it as an escape character. See it's string literal is not properly closed by double quote. What it's trying to do is escape, meaning it's looking for like hard return or a new line or a tab character. We just want a slash, so you do the extra slash in there. Anyways, so we're going to get a reference to our C drive here. We're going to say system out.printline. And we're going to say mDrive.exist. So we're going to say does my C drive exist? Sure enough, it does. Now one thing we kind of want to do here is see the contents of C drive. So we'll say drive. And you see you got all these different methods here. I'm not going to cover all these because there is a lot of them. But you can do things like get the total space, get usable space. Is it a directory? Is it a file? Is it hidden? Is it modified? You can list files. Let's actually go ahead and just list. Now you notice that the list returns strings. So what we can do is list files. Now list files doesn't list files. It lists files and directories. It gives you a list of file objects. I know that's confusing but bear with me. For each file, mFile, we'll call it mReference in driverless files. Now what we're going to do is say if is directory. We're just going to list out the directories here. We'll say system not out.printline. And you can say the name. Whoops. Sorry. There's no name. So we'll say path separator or absolute path. Having some technical difficulties. There we go. Get absolute path. Get name. Get parent. Get path. There are differences between these. For example, if you get name, it's just going to get the name. If you get the path, it'll give you the whole path. So let's just list out the contents of my C drive. Remember, these are just the directories, not the actual files themselves. Now if you wanted to list the files, you could just say .isFile. And that will tell you if it's a file, print it out. So there's the contents of my C drive. There's much more. Obviously, but just for the sake of time, I'm not going to go through them all. Now if you take out the isFile reference and you just go through each one, it's going to give you a mixed match of files and directories here. So you can see you're getting service.log and then C users, C windows. So it's going to just give them all to you. So that in a very brief overview is the file class and how you access files and directories on the hard drive. One thing you should also note is that you can actually use this to create directories. So you can make dir or make dirs. You can delete, delete on exit, things of that nature. So you can do more than just list. Be very careful when using these though, because you could accidentally wipe out your hard drive and that's not cool. This is Brian. I hope you found this tutorial educational and entertaining and thank you for watching.