java while loop try catch, cant print to a new line -
having issue here, need loop print new lines of code file until print 1 line fails on sec time round,
can never print line, below code
public class study { public static void main(string[] args) throws ioexception{ bufferedwriter post = null; file file = new file("text.txt"); if(!file.exists()){ file.createnewfile(); } boolean promptuser = true; filewriter filewriter = new filewriter(file); post = new bufferedwriter(filewriter); seek { while(promptuser){ system.out.println("enter age "); //get age scanner getage = new scanner(system.in); int age= getage.nextint(); if(age <20 || age>50){ //age range system.out.println("age must between 20 , 50"); system.exit(0); } system.out.println("enter name "); //get name scanner getname = new scanner(system.in); string name= getname.nextline(); system.out.println("enter email "); //get email scanner getarea = new scanner(system.in); string email= getarea.nextline(); post.write(age + "\t"); <===== fails here on sec run post.write(name + "\t"); post.write(email + "\t"); post.newline(); post.close(); system.out.println("enter quit quit or key continue"); scanner options = new scanner(system.in); string alternative = options.nextline(); if(option.equalsignorecase("quit")){ system.out.println("goodbye!"); system.exit(0); } } } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); } } }
post.write(age + "\t"); post.newline(); post.write(name + "\t"); post.newline(); post.write(email + "\t"); post.newline();
//remove post.close(); here may solve problem
java
No comments:
Post a Comment