'Java Android create file chmod 666

I can't understand why when saving a file the permissions are not set to 666 Tell me what could be the problem?

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="28"/>

java code:

            if (file.exists()) {
                file.delete();
            }

            file.createNewFile();
            file.setReadable(true);
            file.setWritable(true);
            file.setWritable(true, false);
            file.setReadable(true, false);



            Set<PosixFilePermission> crunchifyPermissions = new HashSet<>();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                crunchifyPermissions.add(PosixFilePermission.OWNER_READ);
                crunchifyPermissions.add(PosixFilePermission.OWNER_WRITE);
                crunchifyPermissions.add(PosixFilePermission.GROUP_READ);
                crunchifyPermissions.add(PosixFilePermission.GROUP_WRITE);
                crunchifyPermissions.add(PosixFilePermission.OTHERS_READ);
                crunchifyPermissions.add(PosixFilePermission.OTHERS_WRITE);
                Files.setPosixFilePermissions(Paths.get(file.getPath()), crunchifyPermissions);
            }
    
            FileWriter writer = new FileWriter(file, true);
            BufferedWriter bufferWriter = new BufferedWriter(writer);
            bufferWriter.append(content);
            bufferWriter.newLine();
            bufferWriter.close();

If I uninstall the app and then install it again. Then, after that, the application does not have access to this file. Despite the fact that I set the rights to 666, they are still set for the user, and not for everyone else.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source