Here you can find the source of getFileExtension(Path path)
Parameter | Description |
---|---|
path | the path. |
Parameter | Description |
---|---|
NullPointerException | if path is null or has zero elements. |
public static String getFileExtension(Path path)
//package com.java2s; //License from project: Open Source License import java.nio.file.Path; public class Main { /**/* w w w . j a va2 s. co m*/ * Gets the file extension of the given path. The extension begins at the last occurrence of ".". Returns an empty * string if the file does not contain a dot (".") or begins with one (hidden file in unix). * * @param path the path. * @return the extension, with leading dot ("."). * @throws NullPointerException if path is null or has zero elements. * @see Path#getFileName() */ public static String getFileExtension(Path path) { String ext = path.getFileName().toString(); int index = ext.lastIndexOf('.'); if (index <= 0) { return ""; } else { return ext.substring(index, ext.length()); } } }