java - Read/Write to a .txt file from JAR -


currently i'm developing java application carry out survey. want read/write .txt file, creating .csv store inputted data. below code have used far write data - of course makes jar file not portable has absolute path.

file file = new file("c:/files/javaapp/src/text.text/"); filewriter fw = null; bufferedwriter bw = null; try {     fw = new filewriter(file, true); } catch (ioexception e) {     system.out.println(e.getmessage()); } bw = new bufferedwriter(fw); try {     bw.write("blah" + ","); } catch (ioexception e) {     system.out.println(e.getmessage()); } try {     bw.newline(); } catch (ioexception e) {     system.out.println(e.getmessage()); } try {     bw.close(); } catch (ioexception e) {     system.out.println(e.getmessage()); } 

i have tried several methods such classname.class.getresource("text.text"); return reflection or nullpointer error.

i know writing file within jar pose problems, meaning have point file outside read/write. don't know how preform in code. need jar file portable. if means must kept within directory, jar can search .txt file within directory. or, there way?

if can me out, grateful.

to read jar file: how read file jar in java?

the file archive file. zip file .jar extension. shouldn't writing it. if jar file has been signed (security projected) cannot write it. changing single bit in file invalidate it.

what should store default file in jar , load "user.home" folder if not there.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -