如何使用JFileChooser查找文件位置 [英] How to use JFileChooser to find a file location

查看:58
本文介绍了如何使用JFileChooser查找文件位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种我可以用来简单地找到文件位置的方法?我正在尝试允许用户选择一个文件并打开它,但是我必须让JFileChooser只是选择该文件并将该位置发送到另一种方法.最好的方法是什么?

Is there a method that i can use to simply find a file location? I'm trying allow the user to choose a file and open it, but I have to have the JFileChooser just choose the file and send the location to another method. What's the best way to do this?

推荐答案

The example in the javadoc show show to do this:

JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
    "JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
   System.out.println("You chose to open this file: " +
        chooser.getSelectedFile().getName());
}

这就是chooser.getSelectedFile()在做什么.取得结果并将其传递给另一种方法.

That's what chooser.getSelectedFile() is doing. Take the result of that and pass it to another method.

这篇关于如何使用JFileChooser查找文件位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆