- 浏览: 148383 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
jinianjun:
请问加的那个函数是什么意思呢?
Linux下DHCP不能自动获取IP问题解决 -
liujiaoshui:
看来你们都没玩过《天龙八部》,那才真 叫一个坑,MB的,有个3 ...
淘宝,真的好烦啊。 -
云中苍月:
呃。。这位仁兄忘性真不小。别怪TB了,自己找个小本本把账号/密 ...
淘宝,真的好烦啊。 -
finallygo:
这也是我不用支付宝的原因
淘宝,真的好烦啊。 -
三单联咖啡色:
涉及到个人财产,还是复杂点的好,自己修改密码都那么麻烦,那其他 ...
淘宝,真的好烦啊。
写道
fileName.replaceAll(".*\\.", "")
评论
21 楼
greatghoul
2011-05-18
感觉iteye里面的越来越多人喜欢扯蛋。。。
20 楼
greatghoul
2011-05-18
duronshi 写道
freish 写道
获取扩展名有啥意义?
赞同,楼主这样获取文件扩展名有何意义?
如果一个exe文件,我将文件后缀改成jpg,那按楼主的方法获取到的是什么?exe or jpg?
如果真的想获取文件扩展名,建议通过文件头里面的标识来获取,可能正确性会高一点。
文件头里的标识不见得就是文件的真实扩展名,这种方法很不准确吧。
19 楼
greatghoul
2011-05-18
yangyi 写道
性能和可读性俱不佳
觉得这方法挺不错,也没有觉得可读性有什么差的,退一步讲,即便差,加个注释就好了。
要说性能吧,那要看什么场景了,脱离的应用场景空谈性能也没有什么意思。
好用就行了。
18 楼
duronshi
2011-05-18
freish 写道
获取扩展名有啥意义?
赞同,楼主这样获取文件扩展名有何意义?
如果一个exe文件,我将文件后缀改成jpg,那按楼主的方法获取到的是什么?exe or jpg?
如果真的想获取文件扩展名,建议通过文件头里面的标识来获取,可能正确性会高一点。
17 楼
xiaobao0501
2011-05-12
org.apache.commons.lang.StringUtils.substringAfterLast("index.htm", ".") ;
16 楼
luciferdevil
2011-05-12
田智伟 写道
貌似可以使用String的 endWith不是来个更简洁?
for example?
15 楼
田智伟
2011-05-12
貌似可以使用String的 endWith不是来个更简洁?
14 楼
zhkchi
2011-05-12
你们老是喜欢喷别人嘛?
13 楼
lyy3323
2011-05-12
indexOfExtension 方法呢,老兄?
12 楼
guoqingcun
2011-05-12
/**
* Gets the extension of a filename.获取文件名
* <p>
* This method returns the textual part of the filename after the last dot.
* There must be no directory separator after the dot.
* 文件名例子:
* foo.txt --> "txt"
* a/b/c.jpg --> "jpg"
* a/b.txt/c --> ""
* a/b/c --> ""
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to retrieve the extension of.
* @return the extension of the file or an empty string if none exists or <code>null</code>
* if the filename is <code>null</code>.
*/
----------------------------------------------------------------------------------
/**
* Returns the index of the last extension separator character, which is a dot.最后"."位置
* <p>
* This method also checks that there is no directory separator after the last dot.
* To do this it uses {@link #indexOfLastSeparator(String)} which will
* handle a file in either Unix or Windows format.
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to find the last path separator in, null returns -1
* @return the index of the last separator character, or -1 if there
* is no such character
*/
------------------------------------------------------------------------------------------
/**
* Returns the index of the last directory separator character.最后目录分割符位置(unix or window)
* <p>
* This method will handle a file in either Unix or Windows format.
* The position of the last forward or backslash is returned.
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to find the last path separator in, null returns -1
* @return the index of the last separator character, or -1 if there
* is no such character
*/
* Gets the extension of a filename.获取文件名
* <p>
* This method returns the textual part of the filename after the last dot.
* There must be no directory separator after the dot.
* 文件名例子:
* foo.txt --> "txt"
* a/b/c.jpg --> "jpg"
* a/b.txt/c --> ""
* a/b/c --> ""
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to retrieve the extension of.
* @return the extension of the file or an empty string if none exists or <code>null</code>
* if the filename is <code>null</code>.
*/
public static String getExtension(String filename) { if (filename == null) { return null; } int index = indexOfExtension(filename); if (index == -1) { return ""; } else { return filename.substring(index + 1); } }
----------------------------------------------------------------------------------
/**
* Returns the index of the last extension separator character, which is a dot.最后"."位置
* <p>
* This method also checks that there is no directory separator after the last dot.
* To do this it uses {@link #indexOfLastSeparator(String)} which will
* handle a file in either Unix or Windows format.
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to find the last path separator in, null returns -1
* @return the index of the last separator character, or -1 if there
* is no such character
*/
public static int indexOfExtension(String filename) { if (filename == null) { return -1; } int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR); int lastSeparator = indexOfLastSeparator(filename); return (lastSeparator > extensionPos ? -1 : extensionPos); }
------------------------------------------------------------------------------------------
/**
* Returns the index of the last directory separator character.最后目录分割符位置(unix or window)
* <p>
* This method will handle a file in either Unix or Windows format.
* The position of the last forward or backslash is returned.
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to find the last path separator in, null returns -1
* @return the index of the last separator character, or -1 if there
* is no such character
*/
public static int indexOfLastSeparator(String filename) { if (filename == null) { return -1; } int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR); int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR); return Math.max(lastUnixPos, lastWindowsPos); }
11 楼
zhang34082
2011-05-12
刚翻了下开源包commons-io-1.4.jar中FilenameUtils类中取扩展名的实现
public static String getExtension(String filename)
{
if (filename == null) {
return null;
}
int index = indexOfExtension(filename);
if (index == -1) {
return "";
}
return filename.substring(index + 1);
}
public static String getExtension(String filename)
{
if (filename == null) {
return null;
}
int index = indexOfExtension(filename);
if (index == -1) {
return "";
}
return filename.substring(index + 1);
}
10 楼
003
2011-05-12
pollyduan 写道
yangyi 写道
性能和可读性俱不佳
还不如fileName.substring(fileName.lastIndexOf(".")+1)来的痛快。
痛快是痛快了,但是当心异常,哈哈,遇上系统文件hosts就崩了
9 楼
nakupanda
2011-05-12
怎么写直观性能又好呢 ?
8 楼
Reset
2011-05-12
楼主刚学会正则 写的一个“Hello, World”鉴定完毕
7 楼
freish
2011-05-12
获取扩展名有啥意义?
6 楼
pollyduan
2011-05-12
yangyi 写道
性能和可读性俱不佳
还不如fileName.substring(fileName.lastIndexOf(".")+1)来的痛快。
5 楼
NanguoCoffee
2011-05-12
helin 写道
grandboy 写道
helin 写道
暂不追求速度。
不追求速度,可读性又不好,为什么要这么写呢?要是我们的员工写成这样,肯定被我骂的。
你会要求你的员工对这句话也加注释吗?
别人说的意思是不能这样获取后缀。
而你的回答却是以这行代码为前提。
4 楼
helin
2011-05-12
grandboy 写道
helin 写道
暂不追求速度。
不追求速度,可读性又不好,为什么要这么写呢?要是我们的员工写成这样,肯定被我骂的。
你会要求你的员工对这句话也加注释吗?
3 楼
grandboy
2011-05-12
helin 写道
暂不追求速度。
不追求速度,可读性又不好,为什么要这么写呢?要是我们的员工写成这样,肯定被我骂的。
2 楼
helin
2011-05-12
暂不追求速度。
发表评论
-
SLF4J这东西太邪恶了
2011-09-02 23:54 882版本弄得乱七八遭的。动不动就报错。 老子恨他不是一年两年了! ... -
每秒多少次是怎么算出来的?
2011-08-05 15:47 1060看到有的大拿写他写的程序执行效率高,每秒多少次,多少次,这个次 ... -
log4j.properties记录
2010-04-06 15:21 890log4j.rootLogger=All,A1,A2,A3 ... -
全面的汉字转拼音与读音包
2009-10-30 23:28 1703最近因需要做汉字转拼音的一个小功能,上网找了一些,不是很好用, ... -
JFreeChart1.0.13API
2009-04-26 01:34 1492方便自己看,也拿出来,方便大家看:)希望有用吧~ -
JTree 的装饰器演示
2009-01-05 10:13 1382今天工作中,遇到小问 ... -
JTree with CheckBox
2009-01-05 08:59 3330Let me explain what is "JT ... -
全半角转换
2008-12-07 21:09 1046[size=medium]/** * 半角转全角 ... -
Java调用jacob出错问题:java.library.path解决
2008-11-10 10:22 8228关于java使用jacob.jar调用word的配置问题 最 ... -
JMF
2008-11-08 23:51 1847Java术语 术语名称:Java媒体框架(JMF) ... -
使用JMF播放音乐
2008-11-08 23:48 4044[size=medium]转载的!! JMF现在还不支持WM ... -
处理文件夹有空格问题及按系统方式打开文件
2008-10-31 09:37 3030[size=medium]取得文件路径: String fil ... -
创建数组的几种方式
2008-10-26 14:35 1265在C语言中: Example: 1、 int nu ... -
java中实现IP地址的各种表现形式之间的转换
2008-10-24 11:34 1335[size=medium]class ip { pri ... -
HttpClient之Session维持
2008-10-23 18:15 10654由于需要,用到了HttpClient在网上查阅了很多资料 ... -
在Swing UI界面定义默认获得焦点的组件
2008-10-23 09:49 8865最近写了个小的UI界面的程序.程序运行后,为方便使用,应该自动 ... -
Serializable java序列化
2008-10-21 14:57 1468[size=medium]Bean Serializable ...
相关推荐
VB简单获取文件扩展名,用法很简单:选择要获得扩展名的文件,点击操作按钮,最后就显示文件的扩展名了,简要说一下原理:从文件名的长度到文件名的第一个字符作循环,如果当前的字符是".",设置变量Ext的值为i,...
这是一个简单的小程序,一直文件的全名,然后通过C语言编程获取它的扩展名
主要介绍了php简单获取文件扩展名的方法,实例分析了php获取文件扩展名的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例总结了PHP获取文件扩展名的常用方法。分享给大家供大家参考,具体如下: 这是我应聘实习时遇到的一道笔试题: 使用五种以上方式获取一个文件的扩展名。 要求:dir/upload.image.jpg,找出 .jpg 或者 jpg , ...
本文档介绍了如何使用Java来获取文件的扩展名。通过阅读本文档,您将学习以下内容: 使用Java的File类来表示文件路径 以字符串形式获取文件的名称和路径 使用字符串处理方法获取文件的扩展名 能学到什么 通过阅读本...
有时候我们需要获取文件的扩展名,分类文件等原因,下面是php的函数实例代码。
主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧,非常简单实用,需要的朋友可以参考下
本文给大家汇总了几种使用PHP实现获取文件的后缀名的方法,十分的简单实用,有需要的小伙伴可以参考下
下面我给各位朋友整理了一篇C# 获取图片文件扩展名的例子,这里方法都非常的简单,我们只用到了image.RawFormat.Guid就实现了,具体看代码 例子 代码如下:/// /// 根据图像获取图像的扩展名 /// /// ”image”> /...
简单获取http://wt4.jb51.net:81/201206/tools/excel2003_jb51.rar此类下载地址返回的扩展名(ContentType值) 文件大小 也可获取各网盘无tools/excel2003_jb51.rar返回的扩展名 支持:百度网盘 360 等 名字带有中文的...
filetype.py Small and dependency free Python package to infer file type and MIME type checking the magic numbers signature of a file or buffer. This is a Python port from ...•提供文件扩展名和MIME类型
对于一张知道全路径的照片,如果其路径包含后缀名的话,要取得后缀名,只需要一行代码即可: 代码如下:var ext = System.IO.Path.GetExtension(“C:\\soar.jpg”);可是,如果这个文件的文件名不包含后缀怎么办? 在...
■ 扩展名变更:包括智能分析文件获取扩展名等高级扩展名变更在内的各种扩展名变更功能 ■ 特定文件文件名变更:包括提取标签给音乐文件批量更名、提取EXIF和IPTC信息给图片文件批量更名、提取多媒体(视频、音频、...
签名 English | 背景 在网络应用程序中,我们接受用户上传的文件, 并且很多时候需要知道用户上传的文件类型。...获取文件扩展名字符串的MIME TYPE var extension = " .jpg " ; var result = extension .
Yii2文件管理器Yii2扩展名,允许与使用简单属性一样处理文件。好处像其他任何简单属性一样使用文件。 存储逻辑是独立的,可以在不更改控制器或视图的情况下进行更改。 格式化程序逻辑是分开的。 您可以为每个文件...
把下面文件另存为mofei.asp文件,运行即可,要FSO支持. <%Function fsofiledatemofei(sfile)'通过FSO得到文件的时间,类型,大小;sfile是文件名'制作:默飞'QQ:33224360'HOME: http://www.8vb.cnsfilere=...
SDS(SQL Data Security)是一...当服务器被盗时,可以是服务器电脑在本公司环境外部无法正常开机,卸载硬盘更换电脑依然无法正常开机,即数据库文件不会被外人获取。 SDS目前支持SQL2000、SQL2005、SQL2008、SQL2012。
一、源码描述 这是一款采用Linq技术实现了获取文件详细信息的小程序,功能比较简单,对于初学Linq的朋友们来说,还是比较有价值的,有需要的朋友可以下载学习一下。二、功能介绍 该源码主要实现了通过选中文件夹,...
另外,里边用上了自编获取文件路径名和扩展名函数 发布前专门测试通过,有需要的朋友可以直接引用 另外说明:由于好用才拿出来共享,为什么说测试无误,因为我最近搞的小程序“文本文件合并”就用到了这段代码。有...