Question

I have built my GUI program and got a runnable jar file but I want to include a txt file that can be edited by the user to the jar file or accompanied with it. this text file can contain a path of an editor that is different between operating systems. Is there a way to do that?

thanks

Was it helpful?

Solution 2

The simplest way is to place the .txt (eg. file.txt) file by the jar, i.e., you can access it in your Java code:

File file = new File("file.txt");

In another way, if you want to launches the associated editor application (default for that file type in the current OS) for editing, you can try the next:

File file = new File("file.txt");    
if (Desktop.isDesktopSupported()) {
    Desktop.getDesktop().edit(file);
}

OTHER TIPS

you cant edit a file and save it inside the jar. what you can do is include your file in the jar with a default data, edit it and save it to a file outside the jar.

actually it is possible if you open the jar itself with the code, and repack it when you change the text, but its like disassemble a car doors, wheels, seats and engine just to put something in the glove box

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top