Skip to content
Mkyong.com
Mkyong.com
  • Development Service
  • Spring Boot
  • Java 8
  • Contact

file metadata

Java – Update last modified date of a file

December 2, 2020June 4, 2010 by mkyong

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

Categories java Tags file metadata, java.io, java.nio, last modified 1 Comment

How to get file creation date in Java

July 23, 2020June 3, 2010 by mkyong

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

Categories java Tags file metadata, io, java, java.io, java.nio 12 Comments

How to get file size in Java

July 23, 2020May 31, 2010 by mkyong

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

Categories java Tags file metadata, file size, io, java, java.io, java.nio 16 Comments

How to get file last modified date in Java

December 2, 2020January 10, 2010 by mkyong

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

Categories java Tags file metadata, java.io, java.nio, last modified 5 Comments

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.

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
  • Spring Guides
  • Docker Hub
  • Maven Central
  • Keep A Changlog
  • Semantic Versioning
  • Hugging Face - Qwen
  • Martin Fowler
About
  • About Us
  • Code License
  • Privacy Policy
  • Terms Of Use
  • Contact Us
© 2026 Mkyong.com - Build with Love.