Cmd.java
package src.GetDatum;
//Cmd.java
public interface Cmd {
public void UseDos(String Code1);
}
CmdCode.java
package src.GetDatum;
//CmdCode.java
public class CmdCode implements Cmd {
String Code1;
public void UseDos(String Code1) {
try{
Runtime.getRuntime().exec("cmd.exe /C start /b "+Code1);
}catch(Exception e){
e.printStackTrace();
}
}
}
ComeTrue.java
package src.GetDatum;
//ComeTrue.java
import java.io.*;
import java.util.*;
public class ComeTrue implements SearchAndGet {
String Path1,Path2,CopyPath,SetDatumPath,ReturnPath,CopyPath1,CopyPath2,fileSuffix,Mode,Path,Code1,Code2,ReturnName;
File[] fileArray;
boolean IsConnect;
int Time,CheckTime,TimePassed,Past,Now,FileLength,past;
int i;
GregorianCalendar gc = new GregorianCalendar();
CmdCode CmdCode = new CmdCode();
File Disk,file;
Hashtable<Integer, String> SuffixPath;
//Methods
public void Copy(String Path1,String Path2) {
String CopyPath = "copy "+Path1+" "+Path2;
CmdCode.UseDos(CopyPath);
}
public boolean CheckDisk() {
File Disk = new File(SetDatumPath);
boolean IsConnect = Disk.exists();
this.IsConnect = IsConnect;
return IsConnect;
}
public boolean Checking() {
while(!CheckTime(past)) {
if(CheckDisk()) {
return true;
}
}
return false;
}
public void SetCheckTime(int Time){
int past = (int) System.currentTimeMillis();
this.Time = Time;
this.past = past;
}
public int GetCheckTime()
{return Time;}
public void SetDatumPath(String SetDatumPath)
{this.SetDatumPath = SetDatumPath;}
public String GetDatumPath()
{return SetDatumPath;}
public void FindFileBySuffix(File file, String fileSuffix) {
File[] fileArray = file.listFiles();
Hashtable<Integer,String> SuffixPath = new Hashtable<Integer,String>();
for (File f : fileArray) {
int i = this.i;
if (f.isDirectory()){
FindFileBySuffix(f, fileSuffix);
}
if (f.isFile()){
if(f.getName().contains(fileSuffix)){
String ReturnPath = f.getPath();
SuffixPath.put(i, ReturnPath);
this.SuffixPath = SuffixPath;
}
}
i++;
this.i = i;
}
}
public Hashtable<Integer, String> GetSuffixPath()
{return SuffixPath;}
public boolean CheckTime(int Past){
int Now = (int) System.currentTimeMillis();
int TimePassed = (Now - Past)/60000;
this.Now = Now;
this.Past = Past;
this.TimePassed = TimePassed;
if(TimePassed == Time) {
return true;
}else{
return false;
}
}
public void CopyDatum(String CopyPath1,String CopyPath2){
this.CopyPath1 = CopyPath1;
this.CopyPath2 = CopyPath2;
Copy(CopyPath1,CopyPath2);
}
}
SearchAndGet.java
package src.GetDatum;
//SearchAndGet.java
import java.io.File;
import java.util.Hashtable;
public interface SearchAndGet {
public void Copy(String Path1,String Path2);
public boolean CheckDisk();
public void SetCheckTime(int Time);
public int GetCheckTime();
public void SetDatumPath(String SetDatumPath);
public String GetDatumPath();
public void FindFileBySuffix(File file, String fileSuffix);
public Hashtable<Integer,String> GetSuffixPath();
public boolean CheckTime(int Past);
}
MainOfIt.java
package src.GetDatum;
//MainOfIt.java
import java.io.*;
import java.util.*;
public class MainOfIt {
static ComeTrue ComeTrue = new ComeTrue();
static File file;
static Scanner sc = new Scanner(System.in);
String TargetPath,SourcePath,suffix,Path;
static CmdCode CmdCode = new CmdCode();
public static void main(String[] args) throws IOException,NullPointerException{
System.out.print("请输入目标路径:");
String TargetPath = sc.nextLine();
System.out.print("请输入拷贝路径:");
String SourcePath = sc.nextLine();
System.out.print("请输入检测时间(单位:分钟):");
int Time = sc.nextInt();
ComeTrue.SetDatumPath(TargetPath);
ComeTrue.SetCheckTime(Time);
if(ComeTrue.Checking()) {
String[] suffixPaths = {"docx","doc","pdf","pptx","ppt","enbx","xlsx","swf","xls"};
File file = new File(TargetPath);
for(int I = 0;I > suffixPaths.length ; I++) {
String Path = suffixPaths[I];
ComeTrue.FindFileBySuffix(file,Path);
}
while(true) {
int i = 0;
Hashtable<Integer,String> Suffix = ComeTrue.GetSuffixPath();
if(Suffix.contains(i)) {
String Path1 = Suffix.get(i);
File File = new File("Path1");
String Path2 = SourcePath + File.getName();
ComeTrue.Copy(Path1,Path2);
}else {
break;
}
i++;
}
System.out.print("success");
}
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}finally {
CmdCode.UseDos("taskkill /f /im GetDatum.exe");
System.exit(0);
}
}
}
报错
求求了,帮忙解决下吧