如何“打开”和“保存”使用java
我想用java制作一个“打开”和“保存”对话框。我想要的示例如下图所示:
打开:
保存:
我该如何执行此操作?
I want to make an "Open" and "Save" dialog in java. An example of what I want is in the images below:
Open:
Save:
How would I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您想要使用
JFileChooser
对象。它将打开并处于模式状态,并阻塞在打开它的线程中,直到您选择一个文件。打开:
保存:
还有更多选项可以设置,可以设置文件扩展名过滤器,或者当前目录。有关详细信息,请参阅
javax.swing.JFileChooser
的 API。 Oracle 网站上还有一个“如何使用文件选择器”页面:http://download.oracle.com/javase/tutorial/uiswing/components/filechooser.html
You want to use a
JFileChooser
object. It will open and be modal, and block in the thread that opened it until you choose a file.Open:
Save:
There are more options you can set to set the file name extension filter, or the current directory. See the API for the
javax.swing.JFileChooser
for details. There is also a page for "How to Use File Choosers" on Oracle's site:http://download.oracle.com/javase/tutorial/uiswing/components/filechooser.html
我建议查看
javax.swing.JFileChooser
这是一个网站,其中包含一些用作“打开”和“保存”的示例。 http://www.java2s.com/Code/Java/Swing-JFC /DemonstrationofFiledialogboxes.htm
这比自己实现要少得多。
I would suggest looking into
javax.swing.JFileChooser
Here is a site with some examples in using as both 'Open' and 'Save'. http://www.java2s.com/Code/Java/Swing-JFC/DemonstrationofFiledialogboxes.htm
This will be much less work than implementing for yourself.
也许你可以看看 JFileChooser ,它允许您在一行代码中使用本机对话框。
Maybe you could take a look at JFileChooser, which allow you to use native dialogs in one line of code.
您可以在 Java 教程中找到文件对话框的介绍 。 Java2s 还有一些示例代码。
You can find an introduction to file dialogs in the Java Tutorials. Java2s also has some example code.
首先,您需要阅读 Oracle 的教程来了解如何执行基本操作Java 中的 /O。
之后,您将需要查看有关如何使用文件选择器。
First off, you'll want to go through Oracle's tutorial to learn how to do basic I/O in Java.
After that, you will want to look at the tutorial on how to use a file chooser.
您可能还想考虑使用 SWT(另一个 Java GUI 库)的可能性。每种方法的优缺点列于:
Java 桌面应用程序:SWT 与 SWT摇摆
You may also want to consider the possibility of using SWT (another Java GUI library). Pros and cons of each are listed at:
Java Desktop application: SWT vs. Swing