你能告诉我,如何保存java swing应用程序中最后选定的文件夹,以便下次启动我的应用程序时自动加载?如何在关闭应用程序后保存上次选择的文件夹?
我正在写一个应用程序,它读取图像并形成幻灯片。我有一切,但记录选定的文件夹?
任何想法?
你能告诉我,如何保存java swing应用程序中最后选定的文件夹,以便下次启动我的应用程序时自动加载?如何在关闭应用程序后保存上次选择的文件夹?
我正在写一个应用程序,它读取图像并形成幻灯片。我有一切,但记录选定的文件夹?
任何想法?
任何想法?
有许多可能的方法,但这里有一对夫妇直截了当的国家:
记录要在一个Properties
对象持久化应用状态。在应用程序退出时,使用其中一种保存/存储方法将属性保存到文件中。当应用程序重新启动时,从文件加载状态...如果存在。
阅读关于Java Preferences的API。
谢谢!有用! – Woytas
我觉得你的最简单的方法是Preferences
类,基本的工作原理是这样的:
//You can get the stored path and for the case there isn´t any you set the default path
Preferences lastdir = Preferences.systemNodeForPackage(Main.class);
String dirStr = lastdir.get("lastdir","c:/default");
//Then you store the new value each time you change the path
lastdir.put("lastdir","c:/new dir");//Stores the new value
退房'Properties'在java中http://docs.oracle.com/javase/ 7 /文档/ API/JAVA/UTIL/Properties.html。可以将状态保存到属性中,并在下次再次读取它。 –
看看[这个讨论](http://stackoverflow.com/questions/19556932/how-to-save-the-state-of-my-minesweeper-game-and-then-load-it/19557052# 19557052)的一些想法。在这种情况下,我倾向于使用'Preferences' API来简化它 – MadProgrammer