java - Feed a Scanner via String -


heres basic goal: convert program uses scanner , keyboard input program uses scanner , java args input. done programatically variety of programs, i'd make few , small changes actual program itself. i'm able changing scanner scanner = new scanner(system.in); scanner scanner = new scanner(args[0]);.

now can seperate each argument space in args[0] , program runs fine, if doesn't use scanner.nextline(). scanner.nextline() used, scanner munches entire string , breaks program.

i can't figure out workaround without changing program structure (removing scanner.nextline()s. there maybe sort of character/sequence stop scanner.nextline(), or process entire string?

thanks

edit: initial idea give scanner string array , have go through that, index index, regardless of method used (next, nextint, nextline). perhaps possible?

  1. look @ apache commons cli, better trying "convert" (kludge) program using scanner.

  2. you can insert newlines in command line arguments if need to.

    public static void main( string[] args ) {   stringbuilder cla = new stringbuilder();    for( string command : args ) {      cla.append( command );      cla.append( '\n' );  // newline   }   string finalcommand = cla.tostring(); } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -