How to read portions of text from a .txt file in Java? -


i wondering, there way read parts of string in .txt file? example, if "1,5,10,20" in .txt file, can tell java save "1" int, save "5" different int, , on? hope made clear enough!

thanks guys!

p.s know how read whole line of text in .txt file in java using bufferedreader, not how read parts of it.

you can use scanner class, provides scanner#nextint() method read next token int. now, since integers comma(,) separated, need set comma(,) delimiter in scanner, uses whitespace character default delimiter. need use scanner#usedelimiter(string) method that.

you can use following code:

scanner scanner = new scanner(new file("demo.txt")); scanner.usedelimiter(",");  while (scanner.hasnextint()) {     system.out.println(scanner.nextint()); } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -