-3

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.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Archagy
  • 135
  • 1
  • 12

2 Answers2

0

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.

Community
  • 1
  • 1
redxef
  • 492
  • 4
  • 12
0

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();
        }
    }
}