📄 cmdhelper.java.svn-base
字号:
package com.onet.autobill.util;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import com.onet.autobill.model.MachineConfig;
public class CmdHelper {
private static Logger logger = Logger.getLogger(CmdHelper.class);
public static boolean makeFolder(String folderName){
File folder = new File(folderName);
if (!folder.exists()) {
if (folder.mkdir() == false){
return false;
}
}
return true;
}
public static int executeCommand(String config) {
int connectFlg = 1;
try {
Process process = null;
Runtime command = Runtime.getRuntime();
process = command.exec(config);
connectFlg = process.waitFor();
} catch (Exception e) {
}
return connectFlg;
}
public static boolean getRemoteServerStatus(MachineConfig machineConfig) {
String connectStr = "net use \\\\" + machineConfig.getMachineName() + " "
+ machineConfig.getMachinePassword() + " " + "/user:"
+ machineConfig.getMachineUser();
int exeFlg = executeCommand(connectStr);
if (exeFlg != 0) {
logger.warn("连接到远程机器失败" + connectStr);
return false;
} else {
logger.info("与远程机器建立连接" + connectStr);
return true;
}
}
public static boolean shutOffServerLink(MachineConfig machineConfig) {
String deleteStr = "net use \\\\" + machineConfig.getMachineName() + " /delete";
int exeFlg = executeCommand(deleteStr);
if (exeFlg != 0) {
logger.warn("与远程机器拆除连接失败" + deleteStr);
return false;
} else {
logger.info("与远程机器连接成功拆除" + deleteStr);
return true;
}
}
public static void clearDirectory(String directoryPath){
File objFile = new File(directoryPath);
try {
FileUtils.cleanDirectory(objFile);
} catch (IOException e) {
}
}
public static boolean copyFile(String src, String obj) {
File srcFile = new File(src);
File objFile = new File(obj);
try {
FileUtils.copyFile(srcFile, objFile);
} catch (IOException e) {
logger.error("复制文件时发生异常", e);
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -