guru java example

Copy file using Runtime class in Java

Welcome to GuruJava.in

Here is the program to copy a file using operation system copy command using java program


public class RuntimeDemo {

public static void main(String[] args) {
try {
// create a process and execute notepad.exe
Process process = Runtime.getRuntime().exec("cmd.exe /c copy HelloWorld.java C:\\Users\\mmansoor\\Desktop");

} catch (Exception ex) {
ex.printStackTrace();
}

}
}

Examples, FAQ, Tutorial, Learning, Questions, Answers from Guru Java