java - copy files preserving time/date information
I need to copy files in Java, preserving time/date information. How do I do this?
Java
Last Comment
MarkLoveExEx
8/22/2022 - Mon
gurpsbassi
have you got any code so far?
This is normally handled as CopyOptions in java
MarkLoveExEx
ASKER
gurpsbassi -- I think your right. I'll be able to test in a couple hours. I THINK the CopyOption for copying attributes was added in Java 7 (I was using Java 6). After I upgraded, the copy attributes was available. I let you know and assign points after I test... Mark
MarkLoveExEx
ASKER
I got the following runtime error:
java.lang.UnsupportedOperationException: COPY_ATTRIBUTES not supported
CEHJ -- I think it said it wasn't supported. These date/time attributes are very important to me, because I need to know when these files arrive on the system. So, I'm trying to use ProcessBuilder to get the linux os to do it. However, I'm having trouble getting it to work. Can you tell what I'm doing wrong?
//Read out dir output
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:\n",
Arrays.toString(command));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
//Wait to get exit value
try {
int exitValue = process.waitFor();
System.out.println("\n\nExit Value is " + exitValue);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
My output:
Output of running [/usr/bin/gunzip, *.gz] is:
This is normally handled as CopyOptions in java