[java] 유닉스/리눅스 시스템 호출을 사용하여 프로세스의 작업 디렉토리를 변경하는 방법에 대해 알려주세요.

프로세스의 작업 디렉토리를 변경하는 가장 간단한 방법은 chdir() 시스템 호출을 사용하는 것입니다.

아래는 해당 방법을 설명하는 간단한 예제 코드입니다.

import java.io.*;

public class ChangeDirectoryExample {
    public static void main(String[] args) {
        File newDir = new File("/path/to/new/directory");
        if (!newDir.isDirectory()) {
            System.err.println("New directory does not exist.");
            return;
        }
        if (!newDir.canRead()) {
            System.err.println("No access to new directory.");
            return;
        }
        boolean success = newDir.setAsCurrentWorkingDirectory();
        if (!success) {
            System.err.println("Unable to change working directory.");
        }
    }
}

이 코드는 주어진 경로에 새 File 객체를 만들고, 해당 디렉토리가 존재하고 읽을 수 있는지 확인한 후 setAsCurrentWorkingDirectory()를 사용하여 프로세스의 작업 디렉토리를 변경합니다.

이 방법을 사용하여 유닉스/리눅스 시스템 호출을 사용하여 프로세스의 작업 디렉토리를 변경할 수 있습니다.