Following program runs the shell copy command "cp" from a java program:
import java.util.regex.*;
import java.io.*;
class ExecDemo {
public static void main(String args[]) {
Runtime r = Runtime.getRuntime();
Process p = null;
try {
File fin = new File("sampleNames.txt");
FileInputStream fis = new FileInputStream(fin);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
String aLine = = null;
String destinationPath = "output/" + "ls_log_untruncated_reshape" + "/";
System.out.println(destinationPath);
while((aLine = in.readLine()) != null) {
String filePath = "input/" +aLine + "/"+ aLine + "_"+"ls_log_untruncated_reshape.txt";
System.out.println(aLine);
String command = "cp " + filePath + " " + destinationPath;
System.out.println(command);
p = r.exec(command);
}
}catch (FileNotFoundException e) {
System.out.println("Cannot find the input file.");
}
catch (Exception e) {
System.out.println("Error running the command.");
}
}
}
References :
Reference 1
Reference 2
Subscribe to:
Post Comments (Atom)
Carlo Cipolla's Laws of Stupidity
"By creating a graph of Cipolla's two factors, we obtain four groups of people. Helpless people contribute to society but are...
-
To install pngwrite we need to install to helper library before we install pngwriter. 1. libpng 2. freetype2 We can use fink or macport to i...
-
"By creating a graph of Cipolla's two factors, we obtain four groups of people. Helpless people contribute to society but are...
-
Use 'Disk Utility' application to format the USB drive in MS-DOS (FAT) format Download the windows ISO file from the Windows websit...
No comments:
Post a Comment