Java Path File Time nio fileCreationTime(Path path)

Here you can find the source of fileCreationTime(Path path)

Description

Return the file creation in millis

License

Apache License

Parameter

Parameter Description
path a parameter

Exception

Parameter Description
IOException an exception

Return

file creation time in millis

Declaration

public static long fileCreationTime(Path path) throws IOException 

Method Source Code

//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);
    }
}

Related

  1. addTimestamp(Path base, TimeUnit unit)
  2. awaitLogMessage(String message, long timeout, Path logFilePath)
  3. getLastAccessTime(Path file)
  4. getLastModificationTime(Path path)
  5. getLastModifiedTime(Path path)
  6. getLastModifiedTimeInMillis(Path path)