java - BufferedWriter is not working -
so writing code acts file system of sorts log in system 2 accounts pre added, both being admins. can create accounts. accounts stored in array list username, , array list password. trying make when export application, when admin adds array list, sends information txt file, next time program run, program load accounts on txt file. have tested loading of accounts, , works fine, cannot seem writing txt file. picked code in method site, im not sure doing wrong:
public static void writefilecontnet(){ string path = "c:\\users\\djandek\\desktop\\loginpro\\info.txt"; bufferedwriter writer = null; try { writer = new bufferedwriter(new filewriter(path, true)); if(!loadfileasstring(path).equals("")){ writer.newline(); } system.out.println(account.accounts.get(account.accounts.size()-1)); writer.write(account.accounts.get(account.accounts.size()-1)); system.out.println(breaker); writer.write(breaker); system.out.println(account.passwords.get(account.passwords.size()-1)); writer.write(account.passwords.get(account.passwords.size()-1)); writer.write(breaker); } catch (ioexception e) { e.printstacktrace(); } bufferedreader in = null; try { in = new bufferedreader(new filereader(path)); } catch (filenotfoundexception e) { e.printstacktrace(); } string line; try { while((line = in.readline()) != null) { system.out.println("it prints this"); system.out.println(line); } } catch (ioexception e) { e.printstacktrace(); } try { in.close(); } catch (ioexception e) { e.printstacktrace(); } }
just wondering println's, console displays: bob; 1q2w; bobspass (the info correct). no errors in console. answer duplicate question, told use file, not how use file. if have data on txt file, reader read , s.o.p it.
you can't write out file inside jar. you'll need give path file on file system.
Comments
Post a Comment