I know Java Applets have a bunch of restrictions as to what they can and cannot access, but I thought JARs were different. For the record, I'm new to JAR files and the like.
I have written a GUI for a data entry tool, and I would like to be able to write the formatted data to a text file. This works when the program is run from Eclipse. However, once packaged in a JAR file, I can no longer get the write-to-file piece to work. It doesn't error out either.
There's no single line of code to share here, but what the program basically allows the user to do is:
- Look at data sheet
- Transpose data into text fields in GUI
- Click save and produce a text file containing this data in my selected directory
That last step is where my runnable JAR is failing me. I click save and my dialog box shows up and everything, but when I check the output folder, no file is produced. NOTE: It does not have to do with an incorrect path--I've checked that. As I said above, it works in Eclipse.
Is there some restriction I'm missing? Ideally I'd be able to share this executable file with a few others to divvy up the data entry task. Is there another format for packaging this program that will allow it to work? (I've spend a long time on this and would like to make it work in Java)
Below is my ActionListener for the save button. This is where the magic should be happening:
class WriteToFileListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String command = event.getActionCommand();
if (command.equals(strWriteToFile)){
System.out.println(strWriteToFile);
int warning = JOptionPane.showOptionDialog(frame, "Text",
"Text", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
if (warning == 0)
{
Path path = Paths.get(tfOutputDir.getText() + "\\" + tfFileName.getText() + ".txt");
ArrayList<String> output = new ArrayList<String>();
for (String s : tmp.items)
{
output.add(s);
}
try {
Files.write(path, output);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}