Avatar of MarkLoveExEx
MarkLoveExEx
 asked on

java - copy files preserving time/date information

I need to copy files in Java, preserving time/date information. How do I do this?
Java

Avatar of undefined
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

I'm on a linux sytem.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
CEHJ

Mark,

I think we've been here before. If the source is not a regular file (e.g. you're reading from an archive) then attributes can't be preserved
MarkLoveExEx

ASKER
I really wish a workaround could be found. Even if third party software must be used.  Mark
CEHJ

Don't you remember we discussed this earlier. Got to go out but back later
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
MarkLoveExEx

ASKER
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?

                  try {
                  String[] command = {"/usr/bin/gunzip", "*.gz"};
              ProcessBuilder probuilder = new ProcessBuilder( command );

              //work directory
              probuilder.directory(new File("/home/public/getweb/Q2/ldm_q2rad_hsr"));
              
              Process process = probuilder.start();
              
              //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:


Exit Value is 1
ASKER CERTIFIED SOLUTION
MarkLoveExEx

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MarkLoveExEx

ASKER
Solution not provided by experts.