I am trying to create a program able to copy a file from one directory to another, but I need to ask the user to select the file, and input the directory. How do i do that?
This is what I have done so far:
import java.io.*;
public class FileCopy {
public static void main(String[] args) {
File file = new File(".");
File copyfile = new File(".");
BufferedReader reader;
PrintWriter writer;
String line;
try{
if (copyfile.createNewFile() || !copyfile.createNewFile()) {
reader = new BufferedReader (new FileReader(file));
writer = new PrintWriter(new FileWriter(copyfile));
while ((line = reader.readLine()) !=null){
writer.println(line);
}
reader.close();
writer.close();
}
}catch(IOException ioEx){
System.err.println("I could not copy the file to a destination directory");
}
enter code here
}
}