Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String getFileName(String url) {
        String fileNameWithExtension = getFileNameWithExtention(url);
        String fileName = fileNameWithExtension;
        if (fileNameWithExtension.contains(".")) {
            fileName = fileNameWithExtension.substring(0, fileNameWithExtension.lastIndexOf("."));
        }
        return fileName;
    }

    public static String getFileNameWithExtention(String url) {
        String fileName;
        int slashIndex = url.lastIndexOf("/");
        int qIndex = url.lastIndexOf("?");
        if (qIndex > slashIndex) {//if has parameters
            fileName = url.substring(slashIndex + 1, qIndex);
        } else {
            fileName = url.substring(slashIndex + 1);
        }
        return fileName;
    }
}