Linux permissions in Java

Overview

I wrote it because I had to code permission changes in Java with my software.

Change the file permissions written on each line of permission.list.

code

    static ArrayList<String> permpaths;

    public static void readPermissionList(){
        permpaths = new ArrayList<>();
        Path p = Paths.get("permission.list");
        if(Files.exists(p)){
            try {
            FileReader fileReader = new FileReader(p.toFile());
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            String data;
            while ((data = bufferedReader.readLine()) != null) {
                System.out.println(data);
                permpaths.add(data);
            }
                fileReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else{
            permpaths.add("pocketmine.yml");
            permpaths.add("server.properties");
            permpaths.add("plugins/ChatPermitter.phar");
        }

    }

    public static void setPermission(){
        for(String filepath :permpaths) {
            try {
                Files.setPosixFilePermissions(Paths.get(filepath),
                        EnumSet.of(PosixFilePermission.OWNER_READ,
                                PosixFilePermission.OWNER_WRITE,
                                PosixFilePermission.OWNER_EXECUTE
                        ));
            } catch (IOException e) {
                System.out.println("error");
            }

reference

https://stackoverflow.com/questions/48945147/how-to-change-permissions-to-incoming-file-in-linux-using-java http://kojiumeda.blogspot.com/2016/10/fileattribute.html http://kagamihoge.hatenablog.com/entry/20130110/1357810886

Recommended literature

https://stackoverflow.com/questions/664432/how-do-i-programmatically-change-file-permissions

Recommended Posts

Linux permissions in Java
Linux permissions
Facade pattern in Java
Singleton pattern in Java
Flyweight pattern in Java
Observer pattern in Java
Use DataFrame in Java
Linux permissions [under investigation]
Iterator pattern in Java
Meaning of Linux permissions
Decorator pattern in Java
Seurat in Linux (installation)
Prototype pattern in Java
Proxy pattern in Java
SSH restrictions in Linux environment
Linux file and directory permissions
Template Method pattern in Java
Linux: DNS replacement in systemd.
Run Amazon Linux 2 in VirtualBox
Meaning of Linux directory permissions
Implement Table Driven Test in Java
Detect and process signals in Java.
Install oracle java8 on amazon linux2
Handle dates in Linux bash commands
Install tensorflow in Docker (LINUX) (memo)
Put only kubectl in Amazon Linux 2
Chain of Responsibility pattern in Java
[Linux] [kernel module] Create kthread in kernel module
Linux
Implemented bubble sort in Java (BubbleSort)
Remote debugging in Visual Studio (Linux)
Linux command (basic in basic) personal memo
Change font size in Serene Linux
Overlapping regular expressions in Python and Java
[Understanding in 3 minutes] The beginning of Linux
Find files like find on linux in Python
[Linux] List of Linux commands used in practice
Express Python yield in JavaScript or Java
Apply Google Java Style formatter in IntelliJ
[Bash / linux] Notes in case of trouble
Differences in syntax between Python and Java
Windows → linux Tips for bringing in data
Get mail using Gmail API in Java
Settings when adding an HDD in Linux
I put Linux (Ubuntu) in VAIO SX14.
Install rJava on Linux in R3.6 environment.
Let's run a Bash script in Java
Communicate with I2C devices in Linux C