File makeFile = new File("d:\\이미지\\test.txt");

try{

makeFile.createNewFile();

}

catch(IOException e){

e.printStackTrace();

}

if(makeFile.exists()){

System.out.println("makeFile이 생성됨");

}

File renameFile = new File("d:\\이미지\\test2.txt");

makeFile.renameTo(renameFile);

try{

renameFile.createNewFile();-----------------1

}

catch(IOException e){

e.printStackTrace();

}

if(renameFile.exists()){

System.out.println("makeFile의 이름이 변경됨");

}

makeFile.renameTo(renameFile);-----------------2

if(renameFile.delete()){

System.out.println("renameFile이 제거됨");


자바 공부하다보니 이런 예제가 있었는데, makeFile.renameTo(renameFile); 이 문구가 어디에 들어가느냐에 따라 결과가 달라지긴 하는데 생각이랑은 달라서

1번에 있으면 원래의 makeFile객체가 renameFile으로 바뀌는거니까 test만 생성됐다 삭제되는건 이해가 되는데

1번에서는 지우고 2번으로 옮기면 test랑 test2가 둘다 생성 된 뒤에 makeFile객체가 renameFile로 바뀌는 거니까 test가 없어져야 될거같지만 test는 남아있더라고

이게 왜 그러는지 설명좀...