Here you can find the source of getNameMinusExtension(File file)
Parameter | Description |
---|---|
file | the File whose name is will be returned |
Parameter | Description |
---|---|
IllegalArgumentException | if file == null |
public static String getNameMinusExtension(File file) throws IllegalArgumentException
/*//from w ww .jav a2s .c om Copyright ? 2008 Brent Boyer This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program 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 Lesser GNU General Public License for more details. You should have received a copy of the Lesser GNU General Public License along with this program (see the license directory in this project). If not, see <http://www.gnu.org/licenses/>. */ import bb.science.FormatUtil; import bb.util.Check; import bb.util.StringUtil; import bb.util.ThrowableUtil; import bb.util.logging.LogUtil; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.util.Random; import java.util.logging.Level; import org.junit.Assert; import org.junit.Test; public class Main{ /** * Returns the file's name minus any extension, that is, the part of its name up to (but not including) the last '.' char. * For example, if presented with a file named "helloWorld.old.txt" then "helloWorld.old" is returned. * If no extension exists (either because there is nothing after the last '.' char or a '.' char never occurs) * then the complete file name (up to but not including any final '.' char) is returned. * Note that the File need not actually exist nor be a normal file. * <p> * @param file the File whose name is will be returned * @throws IllegalArgumentException if file == null */ public static String getNameMinusExtension(File file) throws IllegalArgumentException { Check.arg().notNull(file); String name = file.getName(); int indexPeriod = name.lastIndexOf('.'); if (indexPeriod == -1) return name; else return name.substring(0, indexPeriod); } }