packageLinuxCommand;importsun.awt.image.BufferedImageDevice;import java.io.*;importjava.nio.Buffer;importjava.util.Scanner;import staticcom.sun.deploy.cache.Cache.copyFile;public classMkdir {staticString fileName;staticString command;staticString initPath;staticString aimPath;//mkdir /home/dawn/JavaLinuxCommand/a/b/c//cp /home/dawn/JavaLinuxCommand/src/LinuxCommand /home/dawn
public static void main(String[] args) throwsIOException {
Scanner in= newScanner(System.in);
command=in.nextLine();if (command.startsWith("mkdir")) {
fileName= command.substring(5).replace(" ", "");
File f= newFile(fileName);if (!f.exists()) {
f.mkdirs();
}
}else if (command.startsWith("cp")) {
command= command.substring(2);int start = command.indexOf(" ");
command= command.substring(start + 1);
start= command.indexOf(" ");
initPath= command.substring(0, start);
aimPath= command.substring(initPath.length() + 1);
File scrFile= newFile(initPath);
File destFile= newFile(aimPath);
copyFoder(scrFile, destFile);
}else if (command.startsWith("rm")) {
command= command.substring(2);int start = command.indexOf(" ");
command= command.substring(start + 1);
start= command.indexOf(" ");
initPath= command.substring(0, start);
File filePath= newFile(initPath);
deleteFile(filePath);
}
}private static voiddeleteFile(File filePath) {if(filePath.isDirectory()) {
deleteFile(filePath);
}
filePath.delete();
}private static void copyFoder(File srcFile, File destFile) throwsIOException {if(srcFile.isDirectory()) {
File destFoder= newFile(destFile, srcFile.getName());if (!destFoder.exists()) {
destFoder.mkdir();
}
File[] listFiles=srcFile.listFiles();for(File files : listFiles) {
copyFoder(files, destFoder);
}
}else{
File aimFile= newFile(destFile, srcFile.getName());
copyFile(srcFile, aimFile);
}
}public static void copyFile(File srcFile, File aimFile) throwsIOException {
BufferedInputStream bis= new BufferedInputStream(newFileInputStream(srcFile));
BufferedOutputStream bos= new BufferedOutputStream(newFileOutputStream(aimFile));intlen;byte[] bys = new byte[1024];while ((len = bis.read(bys)) != -1) {
bos.write(bys,0, len);
}
bis.close();
bos.close();
}
}