3

パスボタンをクリックして次の方法を使用します。

public static void pathButtonAction() {
    JFileChooser chooser = new JFileChooser();
    if (pathToInbound == null) { //private static File pathToInbound;
    chooser.setCurrentDirectory(new java.io.File("."));
    } else {chooser.setCurrentDirectory(pathToInbound);
            }

    chooser.setDialogTitle("Choose folder with messages to send");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        pathToInbound = chooser.getCurrentDirectory(); 
        addLogText(chooser.getCurrentDirectory().getAbsolutePath());
    }


}

しかし、ここではフォルダc:\ windows \ tempを選択します。ここでaddLogText(chooser.getCurrentDirectory()。getAbsolutePath())c:\windowsのみをログに記録します。一時フォルダが無視/切り捨てられたのはなぜですか?

4

1 に答える 1

6

chooser.getSelectedFile()の代わりに呼び出す必要がありchooser.getCurrentDirectory()ます。これにより、ユーザーがfilechooserでナビゲートした現在のディレクトリが返されます。あなたの場合はですC:\Windows

于 2010-12-11T21:27:38.847 に答える