Welcome. Today what we're gonna do is I'm going to show you how to make copies of images by writing a program to do so. I've got a file of images on my computer, and I'd like to actually read some of those images in and make copies of those files. So we're gonna do that with a program. So I'm going to create a New Class and we'll call it ImageSaver. And we'll go ahead and open the editor. And let's make it bigger. And what we'll do is we'll create a method in here called doSave, so, And what we're gonna do is we're gonna use our directory resource that we learned about. So I'm going to create, if I can spell it right. I'll create a variable called dr of type DirectoryResource. And I'll have to create a new DirectoryResource. And then we will like to loop over and pick up select files from there. So we'll create a for loop and a variable f which is of type file. And we'll use the selectedFiles method from the DirectoryResource. And let's see what we're gonna do with our files. So, now what we're gonna do is create an ImageResource. I'm gonna create a variable of type ImageResource called image. And that we will have to create a new ImageResource. And we'll use the variable f that we read in in our for loop, and I want to just make sure this works. So what I'm gonna do now is just go ahead and have the image just draw. And so we'll just draw it on the screen and see if this works. All right, so let's see if this works. I'm gonna try and compile it. And nope, I've got an error. So, let's see what it is. So I forgot to put another curly brace. Whenever you get this reached end of file while parsing and it's got this highlighted. So I'm gonna try and add another curly brace, I need one for my method doSave. So let's put that in there. That looks better. You can also tell the way the colors are lined up that I was missing that. So we'll compile it. Okay, so, it's still not compiling because it doesn't know what DirectoryResource is. So I have to import the edu.duke library, so I'll add that right here, import edu.duke.store and that should fix that error. So, let's compile again. Now it can't find file. So I'm also gonna have to import from the java.io library. And I'll just go ahead and specify that I want to import the file class and let's see if that compiles. Yay, no syntax errors. Okay, so now we can come over here and we can actually run this and just see. All this is gonna do, hopefully if it works, is it will just display some images that I'm gonna select. So we will go ahead and create a New Image Saver. And then, we will go ahead and run our doSave method. Now I have to find on my computer where I've got some images. So I'm gonna navigate to here. And I've got it on my desktop, I've got a folder of images. There it is. And now I can select several images. I'll just go ahead and select the dinos. And I'll select another one, eastereggs. I could select as many as I wanted to. And I'll go ahead and open, and our program should just draw these images. And it did. We saw the two images. So, that's great. That seemed to work. I'll just get rid of those. And let's go back to our program now, and now what we would like to do, we know that we can get the images and we can display them. And so now what we'd like to do is we'd like to make a copy of them, so we're gonna add some more code in here. And let's see, okay. So now what we're gonna do is, first, what we have to do is we're gonna get a file name from the image file that we have just grabbed. So, I'm gonna create a string for that file name. And we'll just call that fname. So, the image, we can use the ImageResource method that is called getFileName. And if you didn't know about that you can look in the documentation and you'll see all kinds of methods that you can use with the ImageResource class. So just getFileName should get me a string. And then what we wanna do is we wanna create a new name which is gonna be like copy with the old name. So let's create another string variable. This will be called the newName. And it's gonna be, let's make this string copy-. And then we'll add that to the front of the file name, and the rest of the file name will be the old file name. So let's see, we will call this, fname is the old name. So we've created, all we've done so far, well let's try and run this. Let's see if this works. So if I will just compile this. It compiled with no errors, so let's just run it. We'll come back over here. We will create a New Image Saver. And we'll come over here, and run our doSave method. We can now go pick some files. We have to navigate over to the desktop where my images are in the Images folder. And I can grab, let's see, dinos and eastereggs again. There we go. And we open them. And we got them, and now I also have the Images folder right here, so we can just look and see. We created a new name that was copy of, and if we look in the folder, I don't see any image that's called copy dinos. So we created a string, but we didn't actually use the string to create a new file yet. So let's do that. So we have the name but now we need to use it. So we're going to, actually, there's another method called setFileName. So let's use that. So we'll say image.setFileName, and what we want to set it to is this new string that we created. So let's do that, it's called newName. So that should do it, and now also what we didn't do is we didn't save the file. So we have drawn the file, but there's also a method in the ImageResource class called save. So let's do that too. We'll draw it and we'll save it. And that should save the new file. So let's run this and see if this works. We'll compile it. And then we will come over here and run the program. So we'll create a New Image Saver. And then we'll run our doSave method. We have to find some images. Okay, and so again, I'll just pick dinos and eastereggs, and let's open them. Okay, so, they're displaying again, but how do we know if it worked? Let's go look in the Images folder, which is right here. And if you look in there, you'll see there are two new files in there. One is called copy-dinos and the other is called copy-eastereggs. So it looks like they copied them. Now let's see what happens if we run our program again and we select one of those, or both of those, even. So let me get rid of these old images. And let's just run our program again. So, I'm running the doSave method. I'm going to the desktop, picking some images to make copies of. And I'm just gonna make a copy of copy-dinos. And let's make a copy of copy-eastereggs, and we'll also make a copy of, let's see, rodger. All right, so we're gonna make a copy of those three files. And let's see what happens. Okay, so we had all those pictures pop up. And we'll just get rid of them. And if we look over here in the Images folder, let's see what we have. We have copy-copy-dinos, and we have copy-copy-eastereggs, because we made copies of copies, is what we did. And then we also made a copy of rodger, so we also see copy-rodger. So anyway, that's how you make a copy of an image, where we grab the file, we have to create a new file name, and then we save a copy of it with the new file name. But we have to give it a new name, cuz there's already a file with that name, so we added copy- onto the front of it. Hope you enjoyed that. Thanks.