Java examples for java.nio.file:Path
Returns the file extension of the given file using Regex.
//package com.java2s; import java.nio.file.Path; public class Main { /**/*from ww w .jav a 2s .co m*/ * Returns the file extension of the given file. */ public static String getExtension(Path file) { if (file != null) { String filename = file.getFileName().toString(); String[] tokens = filename.split("\\.(?=[^\\.]+$)"); return tokens.length > 1 ? tokens[1] : ""; } return null; } }