Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Brayden Smith   on Feb 04 In Java Category.

  
Question Answered By: Jeanne Lawson   on Feb 04

the point is that there is no copy.cmd or copy.exe executable files on any windows box!
the commands  like:
cd, cls, date, del, dir, echo, erase, path, prompt, rd etc.
are only interpreted by the executable command.com. however there should be a xcopy.exe on your windows box under the path C:\WINDOWS\system32. so try to run the program with the command: "xcopy sourceFile destinationFile" and then it should work.
however xcopy asks a question:

Does C:\\dst.txt specify a file  name
or directory name on the target
(F = file, D = directory)?

which we should handle as well (before running the code you should of course create a src.txt file on C:\\ directoy):


import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.OutputStream;



public class ProcessTest {



public static void main(String[] args) throws Exception {

Process process = Runtime.getRuntime().exec("xcopy /y c:\\src.txt c:\\dst.txt");

BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));

System.out.println("xcopy says: " + reader.readLine() + " " + reader.readLine());

// and we answer...

OutputStream os = process.getOutputStream();

os.write("F".getBytes());

os.flush();

}
}

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on copy with command prompt Or get search suggestion and latest updates.


Tagged: