로 나는저장 자바 파일
File file = new File("/home/aa.db");
그때 내가
file.delete();
전화를 가지고 있지만 내가 전에이 파일을 저장할 다른 위치에 다른 이름으로 삭제할. - 비주얼 툴없이 코드에서 어떻게 할 수 있습니까?
init 파일을 제거해야하기 때문에 복사가 필요합니다.
는import java.io.File;
public class Example {
public static void main(String[] args) {
File file = new File("C://aa.db");
File tmpFile = new File("C://temp", file.getName());
if(file.renameTo(tmpFile)) {
if(tmpFile.delete()) {
System.out.println(tmpFile.getName() + " was deleted!");
} else {
System.out.println("Delete operation failed.");
}
}
}
}
출력 : aa.db was deleted!
http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#copy –
왜 이름을 변경하지 않습니까? http://stackoverflow.com/questions/1158777/renaming-a-file-using-java – doctorlove
import nio.file을 추가했습니다. 내가 시험해 보는 것보다. (하지만 복사본이 없다) java.nio.file보다 썼다. (하지만 정적 메서드로 여기에 복사본이 없습니다.) = ( – curiousity