List of utility methods to do Scanner Read
String | readFile(String filePath) read File return readFile(new File(filePath)); |
String | readFile(String filePath) Converts the contents of a file into a String. Scanner scanner = null; try { scanner = new Scanner(new File(filePath)).useDelimiter("\\A"); return scanner.next(); } finally { if (scanner != null) { scanner.close(); |
String | readFile(String filePath) Reads the file with the specified path as a String. BufferedReader br = new BufferedReader(new FileReader(filePath)); Scanner sc = new Scanner(br); try { return sc.useDelimiter("\\Z").next(); } finally { sc.close(); br.close(); |
String | readFile(String path) read File return readFile(new File(path)); |
char[] | readFile(String pathname) This method reads a file and returns the file content as char array. File file = new File(pathname); String str = ""; Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { str += scanner.nextLine(); return str.toLowerCase().toCharArray(); |
Scanner | readFile(String project, boolean judge) read File if (judge) return new Scanner(new File("E:\\novice\\judgedata\\" + project + ".dat")); else return new Scanner(new File("sampledata\\" + project + ".dat")); |
String | readFileFully(InputStream stream) read File Fully StringBuilder stringBuilder = new StringBuilder(); try (Scanner scanner = new Scanner(stream)) { while (scanner.hasNext()) { stringBuilder.append(scanner.next()); return stringBuilder.toString(); |
List | readFileToList(File file) read File To List ArrayList<String> list = new ArrayList<>(); try { Scanner scan = new Scanner(file); while (scan.hasNextLine()) { list.add(scan.nextLine()); } catch (FileNotFoundException ex) { return null; ... |
Set | readFileWithoutComments(File input) read File Without Comments Set<String> adsList; try (Scanner scanner = new Scanner(input)) { adsList = new HashSet<String>(10000); final String COMMENT_MARKER = "#"; while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.startsWith(COMMENT_MARKER) || line.isEmpty()) { continue; ... |
String | readFromReader(Scanner scanner) This method is used to read input from buffered reader. String input;
input = scanner.nextLine().trim();
return input;
|