Life is an amazing experience to behold at times. Other times it can be a bit of a nightmare. I guess it all depends on the day, now doesn’t it? Yeah, something like that. Who knows what this life will bring about. I for one don’t know. That’s the big secret behind this life I suppose. But life doesn’t have to be mysterious. Trying to figure out how this life work sat times- can be a nightmare. However all is not lost if you can have hope in something that will make life that much better. If we constantly allow our own thoughts and feelings to fight against us, we will never be better than we currently are. It’s easier said than done naturally. I am my own worst enemy, my worst critic. That’s simply how this life treats me at times. Not much else to comment about that. Am I playing the victim or simply stating the facts? Who can say for sure? I personally feel I’m just telling it like it is, nothing more. Sometimes I can’t determine my own thoughts from that of psychosis . Parts o...
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