package common;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
public class FileCreated {
public Map<String, Object> TestFileCreated (String dir) {
Map<String, Object> returnMap = new HashMap<String, Object>();
boolean createFlag = false;
String fileName = null;
int count = 0;
File fileDir = new File (dir);
long currentTime = System.currentTimeMillis();
long currentTime2 = System.currentTimeMillis();
System.out.println("开始处理");
while (true) {
boolean breakFlag = false;
while (System.currentTimeMillis() - currentTime >= 3000) {
// 处理
System.out.println(count);
String[] returnFile = fileDir.list();
if (returnFile.length != 0) {
File returnCFile = null;
returnCFile = new File (returnFile[0]);
long fileSize1 = returnCFile.length();
long innerCurrentTime = System.currentTimeMillis();
while (System.currentTimeMillis() - innerCurrentTime >= 1000) {
// 延迟1秒
innerCurrentTime = System.currentTimeMillis();
}
returnCFile = new File (returnFile[0]);
long fileSize2 = returnCFile.length();
if (fileSize2 == fileSize1) {
breakFlag = true;
break;
}
}
currentTime = System.currentTimeMillis();
count++;
}
if (breakFlag == true) {
break;
}
}
return null;
}
public static void main (String [] args) {
FileCreated fileCreated = new FileCreated();
fileCreated.TestFileCreated("d:\\filecreate");
}
}
探测文件夹中文件是否copy或者生成完毕
最新推荐文章于 2024-06-18 16:10:07 发布