List of utility methods to do Scanner Read
int[] | readArr(Scanner in, int n) read Arr int[] ar = new int[n]; for (int i = 0; n - i != 0; i++) { ar[i] = in.nextInt(); return ar; |
StringBuilder | readCQLFile(String cqlFileName) read CQL File StringBuilder cypher = new StringBuilder(); try (Scanner scanner = new Scanner( Thread.currentThread().getContextClassLoader().getResourceAsStream(cqlFileName))) { scanner.useDelimiter(System.getProperty("line.separator")); while (scanner.hasNext()) { cypher.append(scanner.next()).append(' '); return cypher; |
String | readFile(Class ownerClass, String fileName) read File String resourcePath = ownerClass.getSimpleName() + "/" + fileName; try (InputStream inputStream = ownerClass.getResourceAsStream(resourcePath); Scanner scanner = new Scanner(inputStream)) { scanner.useDelimiter("\\A"); return scanner.hasNext() ? scanner.next() : ""; |
String | readFile(File f) Read the given file with UTF-8 encoding into a string and return it. StringBuilder sb = new StringBuilder(); Scanner scanner = new Scanner(new FileInputStream(f), "UTF-8"); try { while (scanner.hasNextLine()) { sb.append(scanner.nextLine()).append('\n'); } finally { scanner.close(); ... |
String | readFile(File f) read File Scanner sc = new Scanner(f); StringBuilder sb = new StringBuilder(); while (sc.hasNextLine()) sb.append(sc.nextLine()); sc.close(); return sb.toString(); |
String | readFile(File f) This method reads the contents of a text file. String output = "No final terminator"; try { output = new Scanner(f).useDelimiter("\\Z").next(); } catch (FileNotFoundException e) { System.err.println("Problem reading from file"); return output; |
String | readFile(File file) read File Scanner scanner = new Scanner(file); String text = scanner.useDelimiter("\\A").next(); scanner.close(); return text; |
String | readFile(File file) read File String out = ""; try { FileInputStream r = new FileInputStream(file); out = readStream(r); r.close(); } catch (Exception e) { e.printStackTrace(); return out; |
String | readFile(File file) read File Scanner scanner = new Scanner(file); String ret = scanner.useDelimiter(MULTILINE_START_ANCHOR_REGEX).next(); scanner.close(); return ret; |
String | readFile(File file) Read a file and convert to String StringBuilder result = new StringBuilder(""); Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); result.append(line).append("\n"); scanner.close(); return result.toString(); ... |