Here you can find the source of getPrefix(final Path file, final int filenameSuffixLength)
Parameter | Description |
---|---|
file | path |
filenameSuffixLength | length of the suffix |
Parameter | Description |
---|---|
IllegalArgumentException | file has no filename (probably root of filesystem) |
public static String getPrefix(final Path file, final int filenameSuffixLength) throws IllegalArgumentException
//package com.java2s; /**/*from ww w. j a v a 2 s . c o m*/ * Copyright (C) 2012-2016 Thales Services SAS. * * This file is part of AuthZForce CE. * * AuthZForce CE is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * AuthZForce CE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with AuthZForce CE. If not, see <http://www.gnu.org/licenses/>. */ import java.nio.file.Path; public class Main { /** * Get part of filename before given suffix * * @param file * path * @param filenameSuffixLength * length of the suffix * @return prefix * @throws IllegalArgumentException * file has no filename (probably root of filesystem) */ public static String getPrefix(final Path file, final int filenameSuffixLength) throws IllegalArgumentException { assert file != null; final Path fileName = file.getFileName(); if (fileName == null) { throw new IllegalArgumentException( "Invalid file (no filename, probably root?): " + file); } final String filename = fileName.toString(); return filename.substring(0, filename.length() - filenameSuffixLength); } }