java - Jar file can't write files to local machine -


i know java applets have bunch of restrictions can , cannot access, thought jars different. record, i'm new jar files , like.

i have written gui data entry tool, , able write formatted data text file. works when program run eclipse. however, once packaged in jar file, can no longer write-to-file piece work. doesn't error out either.

there's no single line of code share here, program allows user is:

  1. look @ data sheet
  2. transpose data text fields in gui
  3. click save , produce text file containing data in selected directory

that last step runnable jar failing me. click save , dialog box shows , everything, when check output folder, no file produced. note: not have incorrect path--i've checked that. said above, works in eclipse.

is there restriction i'm missing? ideally i'd able share executable file few others divvy data entry task. there format packaging program allow work? (i've spend long time on , make work in java)

below actionlistener save button. magic should 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>();                 (string s : tmp.items)                 {                     output.add(s);                 }                  try {                     files.write(path, output);                 } catch (ioexception e) {                     e.printstacktrace();                 }             }         }     } } 

okay think have answer own question, don't understand why:

when packaging jar file in eclipse, had chosen "package required libraries generated jar." gave me problem.

in trying again, chose "extract required libraries generated jar." solved problem.

there's explanation of difference between 2 options here, don't understand why affected ability save. perhaps @m0skit0 had point path? have been trying write in jar?


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -