input/output with Java Web Start
-
11-09-2019 - |
Question
I'm working on converting a very simple java desktop application to run in java web start and I'm having all kinds of trouble with the input/output files. Most specifically I can't seem to find any information on how to handle i/o in a web start application. I tried placing the input files in the same folder on my web server as the jar and jnlp file, but it doesn't read it.
I've got one input file that I want to keep on the web server and read into the application from there.
I've got a second file that I want the application to generate on the client machine the first time it's run, and read in from there every time thereafter.
If anyone knows what considerations I need to take for i/o in java web start or can point me towards a resource that explains it I would appreciate it.
Solution
You can find out where you were downloaded from with BasicService
and then use HTTP to transfer the file. You could also just add them to a jar.
You can store a limited amount of information (I think it currently defaults to 128K/muffin) with PeristenceService
.
OTHER TIPS
You don't have many choices.
- You could read the file from http new URL(address).openStream()
- You could embed the file in the jar which I believe you don't want to, and then use getResourceAsStream()
You usually store files on the user hard drive using a hidden folder
public final class ApplicationConstants{
final static String HOMEDIR_STRING = System.getProperty("user.home");
final static File HOMEDIR = new File(HOMEDIR_STRING);
final static File CONFIG_DIR = new File(HOMEDIR, ".com.mycompany.myapp");
}
///
if(!ApplicationConstants.CONFIG_DIR.exists()) ApplicationConstants.CONFIG_DIR.mkdirs();
File outputFile = new File(ApplicationConstants.CONFIG_DIR, "my.xx"));