Copy file into different folder and get the file created time
Here is the code
Code:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class copyFiles {
public static void copy(File source, File dest) {
File cpDestFile = null;
try {
if (dest.isDirectory()) {
if (source.isFile()) {
System.out.println("File name = " + source.getName());
System.out.println("File name dest = " + dest.getPath());
System.out.println("File name cpDestFile = "
+ dest.getPath() + File.separator
+ source.getName());
cpDestFile = new File(dest.getPath() + File.separator
+ source.getName());
} else {
System.out.println("Directory or File Not Found");
return;
}
}
BufferedReader br = new BufferedReader(new FileReader(source));
BufferedWriter bw = new BufferedWriter(new FileWriter(cpDestFile));
int read = 0;
while ((read = br.read()) != -1) {
bw.write(read);
}
br.close();
bw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
copyFiles fcpy = new copyFiles();
File cpSrcFile = new File("D:\\Unprocessed_folder\\text1.txt");
File cpDestDir = new File("D:\\processingfolder");
fcpy.copy(cpSrcFile, cpDestDir);
}
}
and check if any file has been created after a specific time which u need to store in some variable and compare it with file created time with the following code and then copy it into ur destination folder.
Code:
file = "C:\\yourFile.txt";
try
{ //NOTE FILES MUST NOT HAVE SPACES IN THE NAMES OTHERWISE THIS DONT WORK!
Process ls_proc = Runtime.getRuntime().exec("cmd.exe /c dir " + getFilePath() + " /tc");
DataInputStream in = new DataInputStream(ls_proc.getInputStream());
for (int i = 0; i < 5; i++ )
{
in.readLine();
}
String stuff = in.readLine();
StringTokenizer st = new StringTokenizer(stuff);
String dateC = st.nextToken();
String timeC = st.nextToken();//TIME CREATED
in.close();
}
catch (IOException e1)
{
System.out.println("Error in getting create time");
}