IT'S DO
728x90

# StandardCopyOption.REPLACE_EXISTING

Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING);
StandardCopyOption.REPLACE_EXISTING

똑같은 파일(이름 같은것)이 있을때 덮어쓴다.

 

 

# Files.createDirectory

Files.createDirectories(this.fileLocation);
Files.createDirectory(path);

path에 해당하는 디렉토리를 만듬.

 

 

# Files.exists

Path path = Paths.get("/tmp/test.txt");
boolean exists = Files.exists(path, LinkOption.NOFOLLOW_LINKS);

주어진 path에 해당하는 파일이 파일시스템 안에 존재하는지 확인함.

 

 

# Files.copy

    Path source      = Paths.get("/tmp/sourceFile");
    Path destination = Paths.get("/tmp/destinationFile");

try {
        Files.copy(source, destination);
    } catch(FileAlreadyExistsException e) {
        // 파일이 이미 존재하는 경우
    } catch (IOException e) {
        // 뭔가 다른 문제가 발생한 경우
    }

 

source에 해당하는 파일을 destination 폴더에 복사한다.

 

#  Files.move 

    Path source      = Paths.get("/tmp/sourceFile");
    Path destination = Paths.get("/tmp/destinationFile");

try {
        Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        // 실패..
    }

파일의 위치를 이동함.

터미널에서 mv 명령과 같음.

 

#  Files.delete(path)

    Path path      = Paths.get("/tmp/sourceFile");

try {
        Files.delete(path);
    } catch (IOException e) {
        // 실패..
    }

파일을 삭제함.

 

 

# Files.wlakFileTree()

public interface FileVisitor {

    // 디렉토리를 방문하기 전에 호출되는 메소드
    public FileVisitResult preVisitDirectory(
            Path dir, BasicFileAttributes attrs) throws IOException;

    // 파일에 다다랐을 때 호출되는 메소드
    public FileVisitResult visitFile(
            Path file, BasicFileAttributes attrs) throws IOException;

    // 파일에 다다르지 못 했을 때 호출되는 메소드 (권한문제 등)
    public FileVisitResult visitFileFailed(
            Path file, IOException exc) throws IOException;

    // 디렉토리를 방문하고 나서 호출되는 메소드
    public FileVisitResult postVisitDirectory(
            Path dir, IOException exc) throws IOException {
    }

 

https://hbase.tistory.com/43

 

profile

IT'S DO

@멋진놈

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!