[英]How can I run a program that uses JFileChooser class from the command prompt?
I am trying to compile a program that uses the JFileChooser
class in Java from command prompt. 我正在尝试从命令提示符下编译使用Java中的
JFileChooser
类的程序。 My question is that if there is any type of a generic argument I can use for showOpenDialog()
as a component to open a dialogue box. 我的问题是,如果有任何类型的通用参数,我可以将
showOpenDialog()
用作打开对话框的组件。 Here's a sample code: 这是一个示例代码:
public class FileChooser{
public static void main(String args[]) {
JFileChooser chooser = new JFileChooser();
FileReader reader= null;
Scanner scanner= null;
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION){
File file = chooser.getSelectedFile();
try{
reader = new FileReader(file);
} catch (IOException io){
System.out.println("File not found");
}
scanner = new Scanner (reader);
scanner.useDelimiter("\\Z");
String s = scanner.next();
System.out.println(s);
}
scanner.close();
}
}
I assume you are asking for showOpenDialog() argument (not JFileChooser constructor argument). 我假设您要的是showOpenDialog()参数(而不是JFileChooser构造函数参数)。 You can use null.
您可以使用null。 See JFileChooser.showDialog() for more details.
有关更多详细信息,请参见JFileChooser.showDialog() 。 Here's the code you need
这是您需要的代码
JFileChooser chooser = new JFileChooser();
int result = chooser.showOpenDialog(null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.