Java Path File Extention nio getExtension(Path file)

Here you can find the source of getExtension(Path file)

Description

Gets the extension of a file

License

Open Source License

Parameter

Parameter Description
file Path to the file

Exception

Parameter Description
Exception File not have extension

Return

Extension

Declaration

public static String getExtension(Path file) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.file.Path;

public class Main {
    /**/*  ww w.ja va 2 s  . c o m*/
     * Gets the extension of a file
     * 
     * @param file         Path to the file
     * @return            Extension
     * @throws Exception   File not have extension
     */
    public static String getExtension(Path file) {
        String fullFilename = file.getFileName().toString();
        String[] tokens = fullFilename.split("\\.");

        // if the file does not have an extension
        if (tokens.length <= 1) {
            return fullFilename;
        }

        return tokens[tokens.length - 1];
    }
}

Related

  1. fileExtension(final Path thePath)
  2. fileRenamer(final String fromPath, final String toPath, @Nullable final String toExtension, final boolean junkPaths)
  3. findFilesWithExtension(Path directory, String targetExtension)
  4. getAllPaths(Path root, final String... extensions)
  5. getExtension(final Path path)
  6. getExtension(Path path)
  7. getFileExtension(final Path file)
  8. getFileExtension(final Path path)
  9. getFileExtension(Path file)