Requirement background:
Corresponds the data in the database to the associated file path one by one. Such as:
Modify the File_path:/opt/downloads/20121105/001.pdf in table File_config to:/opt/downloads/20121107/001.pdf
This requires two steps, one is to update the database, and the other is to move the file in the database with the path consistent. This seems to be so simple, but in the actual operation of the process has found a problem, Java implementation of Linux commands (such as MV), does not support wildcard characters (such as. *), so you have to execute a MV command for each file.
The Execute MV command in Linux can support wildcard characters (regular expressions), such as: mv/opt/temp/srcpath/*.pdf/opt/temp/destpath/
is entirely possible. But the same operation is done to the Java runtime to perform.
Package com.mss.task;
Import Java.io.BufferedReader;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
public class Testcomman {
/**
* @param args
*
/public static void main (string[] args) {
String Srcpat h = "/opt/temp/srcpath/";
String destpath = "/opt/temp/destpath/";
String command = "mv" + Srcpath + args[0] + " " +destpath;
try {
System.out.println ("Execute command is:" +command);
Runtime Runtime = Runtime.getruntime ();
Process process = runtime.exec (command);
InputStream is = Process.getinputstream ();
BufferedReader reader = new BufferedReader (new InputStreamReader (IS));
String line = "";
while (line = Reader.readline ())!=null) {
System.out.println (line);
}
catch (Exception e) {
E.printstacktrace ();}}
Perhaps the Java runtime has more advanced usage is also unknown, for the moment I did not find a better way to deal with, only one file corresponding to a MV command.