java - PrintWriter: create a file in another package of the same project -
i'm trying create , write on file in bundle using printwriter. code doesn't seem work though:
public void savelevel() { printwriter writer; seek { writer=new printwriter(new file (getclass().getresource("/sections/editor"+editorpanel.level_name+".txt").getpath())); for(int i=0; i<rows; i++){ for(int j=0; j<cols; j++){ if(!map[i][j].equalsignorecase("bird") && !map[i][j].equalsignorecase("bear")){ writer.print(map[i][j]); } } writer.println(); } writer.close(); } grab (filenotfoundexception e) { e.printstacktrace(); } } i end null pointer exception on "getclass().getresource()" line.
java file url printwriter
No comments:
Post a Comment