Here you can find the source of getFileExtension(File file, boolean withDot)
Parameter | Description |
---|---|
file | File to extract extension from |
withDot | If is true then returned extension is proceded by a dot. |
public static String getFileExtension(File file, boolean withDot)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**//w w w.j a v a 2s . c om * Returns extension of specified file. The extension can be returned with or without preceding dot. * @param file File to extract extension from * @param withDot If is true then returned extension is proceded by a dot. * @return extension of specified file */ public static String getFileExtension(File file, boolean withDot) { if (file == null) { return null; } String path = file.getAbsolutePath(); int dotAt = path.lastIndexOf('.'); if (dotAt < 0) { return null; } if (!withDot) { dotAt++; } return path.substring(dotAt); } }