Here you can find the source of nextString(Reader r)
Parameter | Description |
---|---|
r | Reader. |
public static String nextString(Reader r)
//package com.java2s; import java.io.IOException; import java.io.Reader; import java.io.StringWriter; public class Main { /**/*from w ww . jav a2 s .c om*/ * Parse white space delimited String from Reader. * @param r Reader. * @return next non white space String from r. */ public static String nextString(Reader r) { StringWriter sw = new StringWriter(); try { char buffer; int i; // skip white space while ((i = r.read()) > -1) { buffer = (char) i; if (!Character.isWhitespace(buffer)) { sw.write(buffer); break; } } // read non white space, ignore new lines ? while ((i = r.read()) > -1) { buffer = (char) i; if (Character.isWhitespace(buffer)) { break; } sw.write(buffer); } } catch (IOException e) { e.printStackTrace(); } return sw.toString(); } /** * Parse String with given delimiter from Reader. * @param c delimiter. * @param r Reader. * @return next String up to c from r. */ public static String nextString(Reader r, char c) { StringWriter sw = new StringWriter(); try { char buffer; int i; // read chars != c, ignore new lines ? while ((i = r.read()) > -1) { buffer = (char) i; if (buffer == c) { break; } sw.write(buffer); } } catch (IOException e) { e.printStackTrace(); } return sw.toString(); } }