Issue in using the "\n" as a delimiter in java -


this question has answer here:

hi file contents

#nadal\r\n#federer\r\n*#djokovic\r\n#murray\r\n 

i want use \n delimiter want output as

#nadal\r #federer\r *#djokovic\r #murray\r 

i googled not find answer

here code written in java

    scanner scan=null;      scan = new scanner(new filereader("//users//rakesh//desktop//input.txt"));      // initialize string delimiter     scan.usedelimiter(pattern.compile("[\\r\\n;]+"));        // printing delimiter used     system.out.println("the delimiter use "+scan.delimiter());      // printing tokenized stringhashtable     while(scan.hasnext()){         system.out.println(scan.next());     }      // closing scanner stream     scan.close(); 

i getting output whole line instead of in new line.can 1 on tia

your program works fine me, producing 1 output line each input line. except detail that, output lines ended in \r, delimitters must this:

    scan.usedelimiter(pattern.compile("[\\n]+")); 

(the semicolon delimitter no use input format).


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -