java - copy files preserving time/date information

I need to copy files in Java, preserving time/date information. How do I do this?
MarkLoveExExAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
have you got any code so far?
This is normally handled as CopyOptions in java
MarkLoveExExAuthor Commented:
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
MarkLoveExExAuthor Commented:
I got the following runtime error:

java.lang.UnsupportedOperationException: COPY_ATTRIBUTES not supported

I'm on a linux sytem.
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

CEHJCommented:
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
MarkLoveExExAuthor Commented:
I really wish a workaround could be found. Even if third party software must be used.  Mark
CEHJCommented:
Don't you remember we discussed this earlier. Got to go out but back later
MarkLoveExExAuthor Commented:
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
MarkLoveExExAuthor Commented:
gurpsbassi -- CopyOption did not work.
gurpsbassi & CEHJ -- Found a solution. ProcessBuilder couldn't run gunzip directly. I had to put the gunzip command in a bash script. Processbuilder successfully ran the script.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarkLoveExExAuthor Commented:
Solution not provided by experts.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.