从绝对路径获得名,从去年的斜线串,JAVA机器人 [英] Obtain name from absolute path, substring from last slash, java android
问题描述
我要提取的绝对路径名。如果我有一个值的/ mnt / SD卡/视频/ Videoname一个字符串,我要保存的值Videoname的字符串。
该字符串正在改变,我无法获得previously斜线的数量。我怎么能在最后一个斜线分割子?
到/ mnt / SD卡/视频/ Videoname - > Videnoname
块引用>解决方案您应该通过的
文件
API。从<带引号的href=\"http://docs.oracle.com/javase/6/docs/api/java/io/File.html#getName%28%29\"><$c$c>File.getName()$c$c>文档:
返回由此抽象路径名表示的文件或目录的名称。这仅仅是在路径的名称序列中的最后名称。如果路径名的名称序列为空,则返回空字符串。
块引用>例如:
字符串名称=新的文件(到/ mnt / SD卡/视频/ Videoname)的getName();
I want to extract the name of an absolute path. If I have a string with the value /mnt/sdcard/Videos/Videoname, I want to save a string with the value Videoname.
The string is changing and I can't obtain previously the number of slashes. How could I split a substring from the last slash?
/mnt/sdcard/Videos/Videoname --> Videnoname
解决方案You should go via the
File
api. Quoted from theFile.getName()
documentation:Returns the name of the file or directory denoted by this abstract pathname. This is just the last name in the pathname's name sequence. If the pathname's name sequence is empty, then the empty string is returned.
Example:
String name = new File("/mnt/sdcard/Videos/Videoname").getName();
这篇关于从绝对路径获得名,从去年的斜线串,JAVA机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!