Java FileTime.compareTo(FileTime other)

Syntax

FileTime.compareTo(FileTime other) has the following syntax.

public int compareTo(FileTime other)

Example

In the following code shows how to use FileTime.compareTo(FileTime other) method.


//  w w  w. ja  v  a 2 s.  c o m
import java.nio.file.attribute.FileTime;
import java.util.concurrent.TimeUnit;

public class Main {

  public static void main(String[] args) throws Exception {

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);
    
    FileTime fileTime1 = FileTime.from(time,TimeUnit.MILLISECONDS);
    
    
    System.out.println(fileTime.compareTo(fileTime1));

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.nio.file.attribute »




BasicFileAttributes
BasicFileAttributeView
DosFileAttributes
FileTime
PosixFileAttributes
PosixFilePermissions