/**
*
*/
package com.bishal.Test;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
* @author bishal acharya
* This class is used to test whether a file is in copy state
* or Ready state.
*/
public class CopyProgress {
private boolean isFileReady(String filePath) {
File file = new File(filePath);
Scanner scanner;
boolean isCopying = true;
while (true) {
try {
scanner = new Scanner(file);
isCopying = false;
} catch (FileNotFoundException e) {
System.out.println("File not found or is in copy State. ");
sleepThread();
}
if (isCopying == false) {
break;
}
}
System.out.println("copy completed ::");
return isCopying;
}
/**
* sleep for 10 seconds
*/
private static void sleepThread() {
System.out.println("sleeping for 10 seconds");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
CopyProgress cp = new CopyProgress();
cp.isFileReady("C:\\Documents and Settings\\bacharya\\My Documents\\videos\\Se7en.avi");
}
}
Check Output : The output for the project would be
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
File is in copy State.
sleeping for 10 seconds
copy completed ::