List of utility methods to do Path File Read nio
List | readFile(String path) read File List<String> contexts = new ArrayList<>(); try { Stream<String> content = Files.lines(Paths.get(path)); Stream<String> tuples = content.flatMap(line -> { return Arrays.stream(line.split(";")).map(t -> { String[] values = t.split(","); String label = values[0]; String[] predicates = values[1].split("_"); ... |
String | readFile(String path) read File StringBuilder everything = new StringBuilder(); try (InputStreamReader isr = new InputStreamReader( Thread.currentThread().getContextClassLoader().getResourceAsStream(path), Charset.forName("UTF-8")); BufferedReader bufferedReader = new BufferedReader(isr);) { String line; while ((line = bufferedReader.readLine()) != null) { everything.append(line); return everything.toString().replaceAll("\\s", "").replaceAll("\\r|\\n", ""); |
void | readFile(String path) read File Reader reader = new InputStreamReader(new FileInputStream(path), UTF8); try { int c = reader.read(); System.out.println(c); } finally { reader.close(); |
List | readFile(String path) read File List<String> contexts = new ArrayList<>(); try { Stream<String> content = Files.lines(Paths.get(path)); Stream<String> tuples = content.flatMap(line -> { return Arrays.stream(line.split(";")).map(t -> { String[] values = t.split(","); String label = values[0]; String[] predicates = values[1].split("_"); ... |
String | readFileAsString(String filePath) read File As String StringBuilder fileData = new StringBuilder(1000); BufferedReader reader = new BufferedReader(new FileReader(filePath)); char[] buf = new char[1024]; int numRead; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); buf = new char[1024]; ... |
String | readFileAsString(String path) read File As String InputStream is = ClassLoader.getSystemResourceAsStream(path); InputStreamReader inputStreamREader = null; BufferedReader br = null; StringBuilder sb = new StringBuilder(); try { inputStreamREader = new InputStreamReader(is, StandardCharsets.UTF_8); br = new BufferedReader(inputStreamREader); String content = br.readLine(); ... |
List | readFileByLines(String filePath) read File By Lines Path path = new File(filePath).toPath(); return readFileByLines(path); |
String | readFileIntoString(Path path) read File Into String try { return Files.lines(path).collect(Collectors.joining("\n")); } catch (IOException e) { throw new RuntimeException(e); |
List | readFileLines(Path file) Internal method read a file. return Files.readAllLines(file);
|
List | readFileRows(Path path) read File Rows List<String> list = new LinkedList<>(); BufferedReader br = createBufferedReader(path); try { String line; while ((line = br.readLine()) != null) { list.add(line); return list; ... |