The list of methods to do File System are organized into topic(s).
FileSystem
getFileSystem(Path file) get File System
FileSystem fs = null;
try {
URI fileUri = file.toUri();
URI uri = new URI("jar:" + fileUri.getScheme(), fileUri.getPath(), null);
fs = FileSystems.newFileSystem(uri, new HashMap<String, String>());
} catch (Exception e) {
e.printStackTrace();
return fs;
Path
getPath(FileSystem targetFS, String fileName) get Path
String[] nameComps = fileName.replace('\\', '/').split("/");
if (nameComps.length == 1) {
return targetFS.getPath(nameComps[0]);
} else {
return targetFS.getPath(nameComps[0], Arrays.copyOfRange(nameComps, 1, nameComps.length));
Map
loadSystemResourceKeyValueCsvFileToMap(String resourcePath)
Loads the given system resource and assumes it is a csv file with a key and value column.
URL testFileUrl = ClassLoader.getSystemResource(resourcePath);
URI testFileUri = testFileUrl.toURI();
Map<String, Double> results = new HashMap<>();
Files.lines(Paths.get(testFileUri)).forEach(x -> {
String[] strings = x.split(",");
results.put(strings[0], Double.parseDouble(strings[1]));
});
return results;
...
FileSystem
newJarFileSystem(Path jarFilePath) new Jar File System
return FileSystems.newFileSystem(URI.create("jar:" + jarFilePath.toUri().toString()),
new HashMap<String, Object>());
List
systemEnvironmentPaths()
system Environment Paths
List<String> pathStrings = systemEnvironmentPathsAsStrings();
return pathStrings.stream().map(s -> Paths.get(s)).collect(Collectors.toList());