I am writing a cross-platform application that creates temporary files and copies these to another location, where they need to be readable by everyone. (By default, only the owner has read access to temporary files.) I tried using the POSIX file permissions as follows:
FileAttribute<Set<PosixFilePermission>> attrs =
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-r--r--"));
Path temp = Files.createTempFile(null, ".tmp", attrs);
But this results in an exception on non-POSIX platforms:
java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute
I want to add a simple check so that I can use the file permissions where necessary, without breaking compatibility with other platforms.