+ Added file utils and updated localizer format

This commit is contained in:
Matthew Cech
2019-03-30 16:12:45 -07:00
parent d40fbb776c
commit 89ab17829b
3 changed files with 74 additions and 59 deletions
+49
View File
@@ -0,0 +1,49 @@
package utils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.stream.Stream;
public class FileUtils
{
// Reads all lines from a file as a string
public static String ReadContent(Path filePath)
{
StringBuilder contentBuilder = new StringBuilder();
try
{
Stream<String> stream = Files.lines(filePath, StandardCharsets.UTF_8);
stream.forEach(str -> contentBuilder.append(str).append("\n"));
stream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
return contentBuilder.toString();
}
// Recursively acquires all files at and below the specified directory, returning them as an arraylist of paths.
public static ArrayList<Path> AcquireAllFiles(String startingDir)
{
ArrayList<Path> items = new ArrayList<Path>();
try
{
Files.find(Paths.get(startingDir), 999, (path, attributes) -> attributes.isRegularFile()).forEach(items::add);
}
catch (IOException e)
{
e.printStackTrace();
}
return items;
}
}