Skip to content

mkyong.com

  • Spring Boot
  • Java Virtual Threads
  • Contact
  1. Home /
  2. file metadata

Tag: file metadata

j
java June 4, 2010 by mkyong 1 comment

Java – Update last modified date of a file

In Java, we can use the NIO Files.setLastModifiedTime(path, FileTime) to update the last modified date or time of a file. Path path = Paths.get("/path/file"); LocalDate newLocalDate = LocalDate.of(1997, 12, 31); // year, month, dayOfMonth, hour, minute, second LocalDateTime newLocalDateTime = LocalDateTime.of(1999, 9, 30, 10, 30, 22); // convert LocalDateTime to Instant Instant instant = newLocalDateTime.toInstant(ZoneOffset.UTC); […]

Read more Java – Update last modified date of a file
j
java June 3, 2010 by mkyong 12 comments

How to get file creation date in Java

In Java (@since 1.7), we can use the NIO Files.readAttributes to get all the file metadata, including the file creation date. Path file = Paths.get(fileName); BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class); System.out.println("creationTime: " + attr.creationTime()); // creationTime: 2020-07-20T09:29:54.627222Z 1. Files.readAttributes (NIO) This example uses Files.readAttributes to print the file creation date. GetCreationDate1.java package com.mkyong.io.howto; import java.io.IOException; […]

Read more How to get file creation date in Java
j
java May 31, 2010 by mkyong 16 comments

How to get file size in Java

In Java, we can use Files.size(path) to get the size of a file in bytes. // size in bytes long bytes = Files.size(path); 1. Files.size (NIO) This example uses NIO Files.size(path) to print the size of an image file (140 kb). GetFileSize.java package com.mkyong.io.howto; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class GetFileSize […]

Read more How to get file size in Java
j
java January 10, 2010 by mkyong 5 comments

How to get file last modified date in Java

In Java, we can use Files.readAttributes() to get the file metadata or attribute, and then lastModifiedTime() to display the last modified date of a file. Path file = Paths.get("/home/mkyong/file.txt"); BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class); System.out.println("lastModifiedTime: " + attr.lastModifiedTime()); 1. BasicFileAttributes (NIO) This example uses the java.nio.* to display the file attributes or metadata – creation […]

Read more How to get file last modified date in Java

Mkyong.com has provided Java and Spring tutorials, guides, and code snippets since 2008. All published articles are simple, easy to understand, and well-tested in our development environment.

Mkyong.com licenses all source code on this website under the MIT License.

About
  • About Us
  • Code License
  • Privacy Policy
  • Terms Of Use
  • Contact Us
Tools
  • Spring Framework
  • Quarkus Framework
  • Micronaut Framework
  • Oracle Java JDK
  • Eclipse Temurin JDK
  • OpenJDK JDK
  • Hibernate ORM
  • Maven Build Tool
  • Gradle Build Tool
  • Tomcat Application Server
  • Docker
Links
  • Maven Central
  • Docker Hub
  • Spring Guides
  • Quarkus Guides
  • Micronaut Guides
  • Martin Fowler
  • AskPython

© 2026 mkyong.com — Powered by WordPress

RSS