Java - Write code to remove File Name Suffix from path string

Requirements

Write code to remove File Name Suffix from path string

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String srcName = "book2s.com";
        System.out.println(removeFileNameSuffix(srcName));
    }/*  www  .  j a  v a2 s  .  c  om*/

    public static String removeFileNameSuffix(String srcName) {
        int dotIndex = srcName.lastIndexOf(".");
        if (dotIndex == -1)
            return srcName;
        else
            return srcName.substring(0, dotIndex);
    }
}

Related Exercise