른록노트
[Java] 파일이 열려있는지 닫혀있는지 확인하는 방법(파일 사용중인지 아닌지 판별) 본문
// TO CHECK WHETHER A FILE IS OPENED
// OR NOT (not for .txt files)
// the file we want to check
String fileName = "C:\\Text.xlsx";
File file = new File(fileName);
// try to rename the file with the same name
File sameFileName = new File(fileName);
if(file.renameTo(sameFileName)){
// if the file is renamed
System.out.println("file is closed");
}else{
// if the file didnt accept the renaming operation
System.out.println("file is opened");
}
참고사이트
https://stackoverflow.com/questions/1390592/check-if-file-is-already-open
반응형
Comments