java.util.scanner - Java Scanner.next(), printing from while loop -
i started scripting little piece parse old-style .vmg files*. thought start scanner utility @ first chomp out messages 1 one. got.
import java.io.file; import java.io.ioexception; import java.util.scanner; public class strip { public static void main(string[] args) { try { file file = new file("all.vmg"); scanner sc = new scanner(file); // sc.usedelimiter("begin:vmsg"); while (sc.hasnext()) { string string = sc.next(); system.out.println(string); } } catch (ioexception e) { e.printstacktrace(); } } }
it compiles , runs fine. although not print out single thing. first used delimiter commented. thought there might problem that. uses it's default whitespace delimiter. no lines printed anyhow. have guess reason hasnext doesn't evaluate true?. * .vmg files text files in general format of
begin:vmsg version:1.1 x-irmc-status: x-irmc-box:inbox x-nok-dt:20110224t215100z x-message-type:deliver begin:vcard version:3.0 n: tel:+37999999999 end:vcard begin:venv begin:vbody date:24.02.2008 21:51:00 sample mobile text message end:vbody end:venv end:vmsg
i tried feed script several other simple text files nothing printed out.
hasnext()
matches anything. uses pattern (?s).*
when trying matches.
try using hasnextline
uses newline delimiter.
Comments
Post a Comment