I need put one specific image from my project to specific folder in Java. Thanks for helping.
Edit: Im creating a folder with File and the folder I'm creating i need to put an image i have in resources. Thanks for helping.
I need put one specific image from my project to specific folder in Java. Thanks for helping.
Edit: Im creating a folder with File and the folder I'm creating i need to put an image i have in resources. Thanks for helping.
Do you mean to copy the file from 1 location to another? If so, then the approach would be to create a new File
at the desired location, create a FileOutputStream
and write everything from the original File (using an FileInputStream
) to this OutputStream.
Maybe this post can help you out.
You can use NIO package in Java 7 with the class Files
and the static method copy
.
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
public class Main_copie {
public static void main(String[] args) {
Path source = Paths.get("data/image1.png");
Path destination = Paths.get("MyFolder/image1_copied.png");
try {
Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
}