I am writing a small program to copy files. The program checks whether the file to be copied is already copied to the destination location.
To verify if the same file exists, I am comparing following two things:
- Size of the files (of source & destination files).
- Last modified timestamp.
But, I have following problems doing this in Java:
- File.length does not return the same number (a difference of 1 is there) when the files are copied using Java IO (Input/Output stream).
- When the file is copied using Java IO, the last modified timestamp of the copied file is the current date/time instead of the original one.
Please suggest.
you are dealing with text files and do not process correctly new
line character. If you want to copy files you should work with
bytes. Obviously this is assumption only: you have not posted any
piece of your code.
Its last modification date is the date when this file was last
modified, i.e. when you finished to write it. To change is use
File.setLastModifed()method.