Java

Summary

This page contains links to most Java topics. Java, created by James Gosling, among others.

Tools

Concepts

Reference

Get user home directory

System.getProperty("user.home");

List files recursively

try (Stream<Path> walk = Files.walk(Paths.get(input))) {
    List<String> result =
        walk.filter(Files::isRegularFile)
        .map(x ->x.toString())
        .collect(Collectors.toList());
    result.forEach(System.out::println);
} catch (IOException e) {
    e.printStackTrace();
}

In case we want the file subset with a specific extension, txt we can filter the stream with

List<String> result = walk.filter(Files::isRegularFile)
	.filter(x -> x.toString().endsWith(".txt"))
	.map(x -> x.toString())
	.collect(Collectors.toList());

Setting the logger level

From the CLI specify it with, for instance to set the logger level to info:

$ mvn test -Dorg.slf4j.simpleLogger.defaultLogLevel=info