When running Files.walk(Paths.get(\"/var/\")).count() as an unprivileged user, the execution might throw an exception as there are folders inside /var/
There is no easy way to change permissions. Java is not good at these tasks. There are only some tricks like check permissions on start and try to change permissions via su/sudo then restart application or using Java-gnome. Please read a bit more here: Java: Ask root privileges on Ubuntu