Я пытаюсь запустить монитор каталогов из другого java класса. Я хочу передать несколько переменных из моего основного метода в другой другой класс, расположенный в другом каталоге. Я показываю String agr0 thru 4 как переменные, которые я хочу передать. Я хочу передать их в мой класс runmonitor. Любая помощь очень ценится.
private void launch() throws IOException{
String arg0 = "Q:\\tmp\\di1\\DMalone\\Test";
String arg1 = "True";
String arg2 = "True";
String arg3 = "H:;Interior Development;DI;DI1;IP;Dwayne_Malone;CFD_Test";
String arg4 = "Q:;active;p7n;p2;di1";
String command = "cmd /c java -classpath C:\\Users\\ra027233\\CFD\\User_GUI\\Monitor\\build\\classes Monitor";
Process proc;
proc = Runtime.getRuntime().exec(command);
}
public static void main(String[] args){
Monitor monitor_dir = new Monitor();
monitor_dir.runMonitor(args);
}
public void runMonitor(String[] argStrings){
File sourceDir = new File ("Q:\\tmp\\di1\\DMalone\\Test");
//File sourceDir = new File(argStrings[0]);
JOptionPane.showMessageDialog(null,"Launching Monitor_Dir");
boolean isValid = false;
while (isValid == false) {
try {
isValid = fileList(sourceDir);
} catch (IOException e) {
e.printStackTrace();
}
if (isValid == false) {
try {
monitor(sourceDir);
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (copyTempFilesCheck() == true) {
String dpath = "H:;Interior Development;DI;DI1;IP;Dwayne_Malone;CFD_Test";
dpath = dpath.replace(";", "/");
File destDir = new File(dpath);
try {
copyDirectory(sourceDir, destDir);
} catch (IOException ex) {
ex.printStackTrace();
}
}
if (copyActiveFilesCheck() == true) {
String path = "Q:;active;p7n;p2;di1";
path = path.replace(";", "/");
File destDir = new File(path);
try {
copyDirectory(sourceDir, destDir);
} catch (IOException ex) {
ex.printStackTrace();
}
}
JOptionPane.showMessageDialog(null,"Completed!");
}
private static void monitor(File sourceDir) throws IOException {
System.out.println("Start Monitor");
String spath = sourceDir.toString();
Path filePath = Paths.get(spath);
try {
// get watch service which will monitor the directory
WatchService watcher = filePath.getFileSystem().newWatchService();
// associate watch service with the directory to listen to the event
// types
filePath.register(watcher, StandardWatchEventKinds.ENTRY_CREATE);
System.out.println("Monitoring directory for changes...");
// listen to events
WatchKey watchKey = watcher.take();
// get list of events as they occur
List<WatchEvent<?>> events = watchKey.pollEvents();
//iterate over events
for (WatchEvent event : events) {
//check if the event refers to a new file created
if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
//print file name which is newly created
System.out.println("Created: " + event.context().toString());
try {
fileList(sourceDir);
} catch (IOException e) {
e.printStackTrace();
}
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private static boolean fileList(File sourceDir) throws IOException {
System.out.println("Start FileList");
// File folder1 = new File(sourceDir);
File[] listofFiles = sourceDir.listFiles();
ArrayList<String> fileNames1 = new ArrayList<String>();
for (int i = 0; i < listofFiles.length; i++) {
if (listofFiles[i].isFile()) {
fileNames1.add(listofFiles[i].getName());
}
}
boolean isValid;// = false;
if ((fileNames1.indexOf("MasterFile_Complete.sim") > 0)
&& (fileNames1.indexOf("streamlines_scene_UserInput_streamlines_row3.wrl") > 0)) {
isValid = true;
} else {
isValid = false;
}
return isValid;
}
private boolean copyTempFilesCheck() {
boolean copyTempFilesCheck = true;
return copyTempFilesCheck;
}
private boolean copyActiveFilesCheck() {
boolean copyActiveFilesCheck = true;
return copyActiveFilesCheck;
}