Get file name without extension.
Ref:How to get file name without the extension?
Normally,there are two ways to implements this:use the library or the regular expression.
here I use the regular expression.
String s = "a.xml.ac.df.ef";
String result = s.replaceFirst("[.][^.]+$", "");
System.out.println(result);
//outputs:a.xml.ac.df
以上是不考虑到Path, 若有Path,需要先截断路径分隔符,如:
/**获取文件的简短名称,如将"G:\\video_record\\eclipse\\promt-workspace-startup.lxe"转为
* "promt-workspace-startup"
* @param fileFullName 文件的完整路径.
* @return
*/
public static String getFileNameWithoutExtention(String fileFullName) {
//截断路径分隔符.
int backslash = fileFullName.lastIndexOf("\\") != -1 ? fileFullName.lastIndexOf("\\") : fileFullName.lastIndexOf("/");
int dot = fileFullName.lastIndexOf(".");
if (backslash > 0 && dot > 0) {
fileFullName = fileFullName.substring(backslash + 1, dot);
}
return fileFullName;
}
Get file name without extension.的更多相关文章
- 小型文件数据库 (a file database for small apps) SharpFileDB
小型文件数据库 (a file database for small apps) SharpFileDB For english version of this article, please cli ...
- JavaIO之File类
Java-IO之File类 Java-IO之File类 1. File类 1.1. File类说明 1.2. 体验 File 类 1.3. 构造一个 File 类实例: 1.4. 路径: 1.4.1. ...
- Upload file
<h3>Upload File</h3> <form action="@Url.Action("Upload","UploadCo ...
- swift为UIView添加extension扩展frame
添加swift file:UIView+Extension import UIKit extension UIView { // x var x : CGFloat { get { return fr ...
- phpexcel导入excel文件报the filename xxx is not recognised as an OLE file错误。
工作中频繁会用phpexcel类导入excel文件的数据到数据库,目前常用的excel文件格式有:xls.csv.xlsx. 刚开始,针对xls文件,使用如下程序,能正常运行: $objReader ...
- How to upload a file in MVC4
Uploading a file in Asp.Net MVC application is very easy. The posted file is automatically available ...
- How to Create an PostgreSQL Extension
转自:https://severalnines.com/blog/creating-new-modules-using-postgresql-create-extension Extensibilit ...
- java File处理
/**************************************************************************************工具类********** ...
- error items-9022:missing required icon file.the bundle does not contain an app icon for iPhone/iPad Touch of exactly '120x120' pixels,in.pen format for ios versions >= 7.0
error items-9022:missing required icon file.the bundle does not contain an app icon for iPhone/iPad ...
随机推荐
- Energy Minimization
zoj2539:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2539 题意:公式第一项只要当xi=0时才会有作用,第二项只 ...
- php生成的中文文件名会变成乱码,应该这样解决
现在php有很多类库,会生成文件,比如生成zip文件,生成二维码等等.这些类库用起来很爽,但是一旦生成带有中文的文件名,极有可能出现乱码. 问题:生成的中文文件名会变成乱码 解决:使用函数:iconv ...
- log4j学习日记-写入数据库
1.首先创建日志数据库 用的是MySQL CREATE TABLE `td_log` ( `lid` int(11) NOT NULL AUTO_INCREMENT, `lusername` ...
- poj3233
这道题其实算是把快速幂的思想用在多项式之中 A+A^2+A^3+…+A^n=(A+A^1…+A^[n/2])+A^[n/2](A+A+A^1…+A^[n/2])+n mod 2*A^n 然后就是打码的 ...
- Linux Shell编程(26)——代码块重定向
像 while, until, 和 for 循环代码块, 甚至 if/then 测试结构的代码块都能做到标准输入的重定向. 即使函数也可以使用这种重定向的格式 .所有的这些依靠代码块结尾的 < ...
- mkfs 的使用
使用方法: [root@localhost beinan]# mkfs -t 文件系统 存储设备 注:这里的文件系统是要指定的,比如 ext3 :reiserfs :ext2 :fat32 :msd ...
- JAVA中ProcessBuilder执行cmd命令找不到路径的解决方法
今天遇到了一个很奇葩的问题,终于解决了,记一下,以做备忘. 前提条件:工程路径在D盘下 cmd要执行的可执行文件路径不在D盘下 然后...出事了............................ ...
- HDOJ 2010 水仙花数
Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: "水仙花数"是指一个三位数,它的各位数字的立方和等于其本 ...
- vijosP1014 旅行商简化版
vijosP1014 旅行商简化版 链接:https://vijos.org/p/1014 [思路] 双线DP. 设ab,ab同时走.用d[i][j]表示ab所处结点i.j,且定义i>j,则有转 ...
- Eclipse Maven插件无法搜索远程库
创建Maven工程,发现添加依赖“Add Dependency”的时候无法自动搜索远程库. 导致此问题的可能原因: 1.update index的时候失败了. 解决:打开Window/Show Vie ...