这段代码不是我自己的。学分:Java Swing – JFileChooser 示例
JFileChooser jfc = new JFileChooser(
FileSystemView.getFileSystemView().getHomeDirectory());
请解释这行代码。我知道它是方法链接,但是FileSystem
对象是否正确?
那么,该JFileChooser
对象将FileSystemView
具有两个链式方法的对象作为它的参数吗?
getFileSystemView()
方法调用getHomeDirectory()
方法吗?
FileChooser1
package com.mkyong.jfileChooser;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileSystemView;
public class FileChooser1 {
public static void main(String[] args) {
JFileChooser jfc = new JFileChooser(
FileSystemView.getFileSystemView().getHomeDirectory());//<--p
int returnValue = jfc.showOpenDialog(null);
// int returnValue = jfc.showSaveDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfc.getSelectedFile();
System.out.println(selectedFile.getAbsolutePath());
}
}
}