List of utility methods to do Path File Content
void | appendToLog(String content, Path newFile) append To Log try (BufferedWriter writer = Files.newBufferedWriter(newFile, Charset.defaultCharset(), new OpenOption[] { StandardOpenOption.APPEND })) { writer.append(content); writer.append("\n"); writer.flush(); } catch (IOException exception) { System.out.println("Error writing to file"); |
void | assertSameContent(String expectedFilePath, String actualFilePath) assert Same Content assertSameContent(new File(expectedFilePath), new File(actualFilePath)); |
boolean | contentEquals(Path leftPath, Path rightPath) content Equals boolean leftExists = Files.exists(leftPath); boolean rightExists = Files.exists(rightPath); if (!leftExists && !rightExists) { return true; if (leftExists != rightExists) { return false; if (Files.isSameFile(leftPath, rightPath)) { return true; try (BufferedReader leftStream = Files.newBufferedReader(leftPath); BufferedReader rightStream = Files.newBufferedReader(rightPath)) { for (;;) { String leftLine = leftStream.readLine(); String rightLine = rightStream.readLine(); if (leftLine == null && rightLine == null) { return true; if ((leftLine == null) != (rightLine == null)) { return false; assert leftLine != null && rightLine != null; if (!leftLine.equals(rightLine)) { return false; |
String | fileContent(final Path p) Read a file content, or wait the file to be created. if (p == null) { throw new IllegalArgumentException(); if (Files.exists(p)) { return readAndDelete(p); final Path parent = p.getParent(); if (Files.notExists(parent)) { ... |
String | fileContent(final String filePath) file Content return Resources.toString(Resources.getResource(filePath), Charset.defaultCharset());
|
String | getContent(Path path) get Content String textReturned = null;
textReturned = java.nio.file.Files.lines(path).collect(Collectors.joining());
return textReturned;
|
String | getFileContents(final String absFilePath) get File Contents String data = null; if (absFilePath != null) { File file = new File(absFilePath); if (file.isFile()) { byte[] buffer = new byte[4096]; BufferedInputStream bis = null; try { int readSize = 0; ... |
String | getFileContents(Path file) get File Contents try (BufferedReader in = newBufferedReader(file, Charset.defaultCharset())) { StringBuffer sb = new StringBuffer(); String line; while ((line = in.readLine()) != null) { sb.append(line); return sb.toString(); |
String | getFileContents(String path) get File Contents String returnString = null; File file = new File(path); if (file.exists() && file.isFile()) { BufferedReader fileBufferedReader = null; try { fileBufferedReader = Files.newBufferedReader((FileSystems.getDefault().getPath(path)), Charset.forName("utf-8")); StringBuffer sb = new StringBuffer(); ... |
List | listUris(Path content) Lists URIs relative to the given Path . List<Path> paths = listFiles(content); List<String> result = new ArrayList<>(); for (Path path : paths) { String uri = toUri(path, content); result.add(uri); return result; |