0
我想創建一個程序能夠將文件從一個目錄複製到另一個目錄,但我需要讓用戶選擇文件並輸入目錄。我怎麼做?用戶輸入文件/目錄
這是我迄今所做的:
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
}
}