JFileChooserユーザーが使用して選択したフォルダーを取得し、同じ方法で選択した宛先にコピーするバックアッププログラムを取得しようとしています。
唯一の問題は、選択したフォルダーのすべてのコンテンツが同じ名前のフォルダーに入れられないことです。その理由は本当にわかりません。私はいくつかのグーグルをしましたが、役に立つものは何も見つかりませんでした。
コードは次のとおりです。
package main;
import java.io.File;
import java.util.ArrayList;
public class test {
BackgroundWorker bw;
static ArrayList bgWorker = new ArrayList();
ArrayList al = new ArrayList(); // this is the list of files selected to
                                // back up
String dir = ""; // this is the path to back everything up to selected by
                    static // the user
boolean bwInitiallized = false;
public void startBackup() throws Exception {
    Panel.txtArea.append("Starting Backup...\n");
    for (int i = 0; i < al.size(); i++) {
        /**
         * THIS IS WHERE I NEED TO CREATE THE FOLDER THAT EACH BACKUP FILE
         * WILL GO INTO EX: SC2 GOES INTO A FOLDER CALLED SC2 AND RIOT GOES
         * TO RIOT, ALL WITHIN THE DIRECTORY CHOSEN
         */
        File file = new File((String) al.get(i));
        File directory = new File(dir);
        // File dirFile = new File(dir + "\\" + file.getName());
        // if (!dirFile.exists())
        // dirFile.mkdir();
        bw = new BackgroundWorker(Panel.txtArea, file, directory);
        bgWorker.add(bw);
        bwInitiallized = true;
        bw.execute();
        /**
         * follows to the bottom of the txtarea
         */
        int x;
        Panel.txtArea.selectAll();
        x = Panel.txtArea.getSelectionEnd();
        Panel.txtArea.select(1, x);
    }
    clearList(); // method not included in this example that deletes all the
                    // contents of the al array list.
}
public static void cancel() {
    BackgroundWorker bg;
    if (bwInitiallized) {
        bwInitiallized = false;
        Panel.txtArea.append("Cancelling...\n");
        for (int i = 0; i < bgWorker.size(); i++) {
            // BackgroundWorker bg = (BackgroundWorker) bgWorker.get(i);
            bg = (BackgroundWorker) bgWorker.get(i);
            bg.cancel(true);
        }
        Panel.txtArea.append("Canceled backUp!\n");
    } else {
        Panel.txtArea.append("Cannot Cancel! Not Initiallized!\n");
    }
}
}
私が問題だと思うのは、何らかの理由で宛先ファイルパスに含まれるフォルダーの名前が必要であると信じていますが、それを試してみましたが、役に立ちませんでした。
私が間違っていることを誰かが知っていますか?
これは、JFileChooser次のコードです。
public void fileChooserToDestination() {
    LookAndFeel previousLF = UIManager.getLookAndFeel();
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }
    JFileChooser jfc = new JFileChooser();
    try {
        UIManager.setLookAndFeel(previousLF);
    } catch (UnsupportedLookAndFeelException e) {
    }
    jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (jfc.showDialog(null, "Select Directory") == JFileChooser.APPROVE_OPTION) {
        File file = jfc.getSelectedFile();
        dir = file.getPath();
        Panel.txtArea.append("User selected " + file.getPath()
                + " for the destination...\n");
        try {
            startBackup();
        } catch (Exception e) {
        }
    } else {
        Dialogs.msg("You canceled selecting a destination folder! Returning to main screen...");
        al.clear();
        Panel.txtArea.append("User cancelled the destination selection..."
                + "\n");
    }
    return;
}