Can't Read File After Building in java -
hey guys i've program read file
public static string readfileasstring(string filename){ bufferedreader reader; try { reader = new bufferedreader(new filereader(filename)); string line; stringbuilder sb = new stringbuilder(); while ((line = reader.readline()) != null){ sb.append(line + "\n"); } reader.close(); return sb.tostring(); } catch (filenotfoundexception ex) { joptionpane.showmessagedialog(null, "file not found","error",joptionpane.error_message); } catch (ioexception ex) { logger.getlogger(tsst.class.getname()).log(level.severe, null, ex); } return null; } and constructor
public tsst() { initcomponents(); joptionpane.showmessagedialog(null, readfileasstring("test.txt"),"succes",joptionpane.default_option); } and file in application project if run file netbeans it's work normaly got need if build application got jar file , run got error file not found , same in writing
public static void writefile(string canonicalfilename, string text){ file file = new file (canonicalfilename); bufferedwriter out; try { out = new bufferedwriter(new filewriter(file)); out.write(text); out.close(); } catch (ioexception ex) { logger.getlogger(tsst.class.getname()).log(level.severe, null, ex); } }
you're working netbeans thing after build application folder creat called dist here put test.txt
Comments
Post a Comment