2009penguin 2022-11-21 22:40 采纳率: 54.5%
浏览 9

改一下BUG,能运行就行

写程序时遇到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

现在直接卡死

img

我的解答思路:无

尝试过的方法:改语法,方法

从TargetPath拷贝后缀为"docx","doc","pdf","pptx","ppt","enbx","xlsx","swf","xls"的文件到SourcePath
  • 写回答

1条回答 默认 最新

  • 「已注销」 2022-11-22 08:13
    关注

    打断点就行

    评论

报告相同问题?

问题事件

  • 创建了问题 11月21日

悬赏问题

  • ¥50 前后端数据顺序不一致问题,如何解决?(相关搜索:数据结构)
  • ¥15 基于蒙特卡罗法的中介效应点估计代码
  • ¥15 罗技G293和UE5.3
  • ¥20 Tesla 特斯拉K80显卡 如果需要使用该设备,你需要禁用系统上的另一个设备。
  • ¥30 QT调用百度智能云千帆模型无法取得返回文本
  • ¥50 CCD工业视觉相机检测出现光边
  • ¥60 二次元手游日常任务自动化代肝(相关搜索:自动化)
  • ¥15 mysql将查询的结果作为动态列名怎么实现
  • ¥50 python自动地图截图脚本
  • ¥15 fastreport怎么判断当前页数