Here you can find the source of fileCreationTime(Path path)
Parameter | Description |
---|---|
path | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static long fileCreationTime(Path path) throws IOException
//package com.java2s; /*//w w w. ja v a 2 s . com * Copyright (c) 2012-2017 ZoxWeb.com LLC. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.concurrent.TimeUnit; public class Main { /** * Return the file creation in millis * @param file * @return file creation time in millis * @throws IOException */ public static long fileCreationTime(File file) throws IOException { if (!file.exists()) { throw new FileNotFoundException(); } return fileCreationTime(file.toPath()); } /** * Return the file creation in millis * @param path * @return file creation time in millis * @throws IOException */ public static long fileCreationTime(Path path) throws IOException { BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class); return attributes.creationTime().to(TimeUnit.MILLISECONDS); } }