Here you can find the source of fileExtension(final Path thePath)
Parameter | Description |
---|---|
thePath | path of the file to check the extension |
public static String fileExtension(final Path thePath)
//package com.java2s; /*//from w w w. j a va 2s .c om * Copyright (c) 2013 christianr. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v3 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-3.0.html * * Contributors: * christianr - initial API and implementation */ import java.nio.file.Path; public class Main { /** * Gets the extension of the given file. * @param thePath path of the file to check the extension * @return the extension of the file */ public static String fileExtension(final Path thePath) { if (thePath == null) return null; if (thePath.getFileName() == null) return null; String myPathString = thePath.getFileName().toString(); if (myPathString.lastIndexOf(".") < 0) return null; return myPathString.substring(myPathString.lastIndexOf(".") + 1, myPathString.length()); } }