Is file a symbolic link

File meta data is stored within the file system and directories. It tracks information about each of the file which is typically referred to as file attributes. File attributes include size of a file, is it a directory, a symbolic link, a regular file, determine if the file is hidden, retrieve the last modified time and find when a file was created.

Setup

private static final String SOURCE = "com/levelup/java/io/is-symbolic-link.txt";

Path source;

@Before
public void setUp() throws IOException, URISyntaxException {

    source = Paths.get(this.getClass().getClassLoader().getResource(SOURCE)
            .toURI());
}

Straight up Java

@Test
public void file_is_symbolic_link_nio() throws IOException {

    BasicFileAttributes attr = Files.readAttributes(source,
            BasicFileAttributes.class);

    boolean isSymbolicLink = attr.isSymbolicLink();

    assertFalse(isSymbolicLink);
}

Java 7 File I/O

@Test
public void file_is_symbolic_link_nio_files () throws IOException {

    boolean isSymbolicLink = Files.isSymbolicLink(source);

    assertFalse(isSymbolicLink);
}

Apache Commons

@Test
public void file_is_symbolic_link_apache_commons() throws IOException {

    boolean isSymbolicLink = FileUtils.isSymlink(source.toFile());

    assertFalse(isSymbolicLink);
}