file io - nextLine ignored in Java when asking for input -
below see code having trouble with. basic idea simple copy of 1 existing text file new one, if new 1 exists, given 3 options. other switch cases work flawlessly, third , final case not work want @ all!
basically choice lets pick new file name if chosen 1 existed, when pick 3 option first print out line "type new name:" , skips filenotfoundexception
catch, bypassing code should allow user enter new name, have no idea why. suggestions?
system.out.println("type new name:"); string retryname = keyboard.nextline(); try { outputstream = new printwriter(retryname); } catch (filenotfoundexception e) { system.out.println("error creating file " + retryname + "!"); system.out.println("the program close."); system.exit(0); } while (inputstream.hasnextline()) { outputstream.println(inputstream.nextline()); }
have @ retryname before try / catch; retryname contain? bet contains new line not capturing part of code lets user pick option earlier in code.
Comments
Post a Comment