This life is here for a reason, we don’t have to say exactly what that reason is, we just have to believe in it no matter what happens in this life, we have to understand one thing. That thing is that we are not alone in the universe. I’m not saying there are aliens out there, but yeah there are aliens out there. It’s a concept that people have wondered about from time to time, there doesn’t appear to be anything else you can do but wonder what’s going on in the skies above us! There are so many things in this life that don’t always seem to matter, but you wish they would, at least that’s what I’d like to think would happen. I’m not sure that’s how this life is meant to be understood of course. If there’s anything in this life that doesn’t make sense, then it will always be there. It doesn’t have to make sense, that’s the absurdity of it all! Why should it make sense if there’s nothing to grasp from it all? I’m not sure I know the ansewr to that question. Such a life comes and goes an...
Sometimes you want to be able to change the created date of a file. Don't ask me WHY you would ever need to do this, but well here's a way in Java.
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.time.*;
public class ChangeCreatedDate {
public static void main(String[] args) throws IOException {
if (args.length == 2) {
File file = new File(args[0]);
if (file.exists()) {
file.setLastModified(System.currentTimeMillis());
} else {
file.createNewFile();
}
}
LocalDate date = LocalDate.parse(args[1]);
LocalTime time = LocalTime.now();
Path file = Paths.get(args[0]);
FileTime fileTime = FileTime.fromMillis(getMillisecondsSince1970(date, time));
Files.setAttribute(file, "creationTime", fileTime);
}
public static long getMillisecondsSince1970(LocalDate date, LocalTime time) {
ZonedDateTime zonedDateTime = ZonedDateTime.of(
date,
time,
ZoneId.systemDefault());
return zonedDateTime.toInstant().toEpochMilli();
}
}
Looking back at it, I wonder why I didn't make it so you could update the time as well as the date. Interesting. I mean it would make sense to be able to update both the date AND time. But I didn't have that in this section of code. Oh well, I'm sure I'll change it someday.
I find it interesting that we're updating an attribute of the file. One would think it would be someplace else, or easier to access directly on the file object itself. But well, it's not. So that's just that.
Comments
Post a Comment