【发布时间】:2011-05-22 21:57:26
【问题描述】:
现在,我有一个设置的类路径,但我想弹出一个打开的文件,让用户选择要打开的文件。我已经尝试过 JFileChooser,但到目前为止还没有成功。这是我的代码:
public static void main(String[] args) throws IOException {
JFileChooser chooser = new JFileChooser();
int returnValue = chooser.showOpenDialog( null ) ;
if( returnValue == JFileChooser.APPROVE_OPTION ) {
File file = chooser.getSelectedFile() ;
}
// I don't want this to be hard-coded:
String filePath = "/Users/Bill/Desktop/hello.txt";
我该怎么做呢?
【问题讨论】:
标签: java file-io jfilechooser openfiledialog