Here you can find the source of getExtension(Path file)
Parameter | Description |
---|---|
file | Path to the file |
Parameter | Description |
---|---|
Exception | File not have extension |
public static String getExtension(Path file)
//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]; } }