In my program there's requirement to read file content at the time of program startup. Right now file is loaded in the constructor. Since file is a bit huge and I/O is being performed so it takes a bit of time to show screen.
My question is, can I use Preference API as an aternative of file I/O? Since content is not changed frequently so I want to avoid I/O unless it's asked by user. I would like to load content once if preference not set and as long as preference is not empty it fetches content from Preference rather than file.
Share your thoughts.
@Zhedar's point about Preferences
is well taken. Instead, load the file in the background using SwingWorker
, as shown here. With suitable granularity in publish()
and process()
, results can begin appearing immediately. The GUI will remain responsive while the remainder of the file loads.