Java Utililty Methods Scanner Read

List of utility methods to do Scanner Read

Description

The list of methods to do Scanner Read are organized into topic(s).

Method

ListgetStreamLines(final InputStream is)
get Stream Lines
return getStreamLines(is, DEFAULT_ENCODING);
ScannergetThreadScanner()
get Thread Scanner
long threadId = Thread.currentThread().getId();
Scanner keyboardScanner = map.get(threadId);
return keyboardScanner;
Stringload(Class cls, String location)
load
try (InputStream is = cls.getResourceAsStream(location);
        Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A");) {
    return s.hasNext() ? s.next() : "";
} catch (Exception ex) {
    throw new RuntimeException(ex);
Stringload(File in)
Used to load the entire file into String object
Scanner sc = new Scanner(in);
StringBuilder sb = new StringBuilder();
while (sc.hasNextLine()) {
    sb.append(sc.nextLine()).append("\n");
return sb.toString();
Stringload(final String fileName)
load
try (Scanner scanner = new Scanner(new File(fileName))) {
    final StringBuilder builder = new StringBuilder();
    while (scanner.hasNextLine())
        builder.append(scanner.nextLine()).append("\n");
    return builder.toString().trim();
ArrayListload(InputStream in, int elementCountOverride)
load
Scanner scan = new Scanner(in);
Map<String, String> parameters = getParameters(scan, null);
int elements = elementCountOverride;
return loadElements(scan, elements, 0);
AWSCredentialsloadAWSCredentails(String file_path)
load AWS Credentails
FileInputStream fin = new FileInputStream(file_path);
Scanner scan = new Scanner(fin);
String id = scan.next();
String key = scan.next();
fin.close();
return new BasicAWSCredentials(id, key);
boolean[]loadBooleanArray(BufferedReader in)
load Boolean Array
try {
    int dim = Integer.parseInt(in.readLine());
    String[] vals = in.readLine().split("\\s+");
    boolean[] ret = new boolean[dim];
    for (int i = 0; i < ret.length; i++) {
        ret[i] = Boolean.parseBoolean(vals[i]);
    return ret;
...
voidloadConf()
load Conf
if (conf == null)
    conf = new HashMap<String, String>();
File file = new File(confPath);
Scanner reader = new Scanner(file);
while (reader.hasNextLine()) {
    String line = reader.nextLine().trim();
    if (line.length() == 0)
        continue;
...
double[]loadDoubleArray(Scanner reader)
load Double Array
int dim = reader.nextInt();
double[] ret = new double[dim];
for (int i = 0; i < dim; i++) {
    ret[i] = Double.parseDouble(reader.next());
return ret;