English 中文(简体)
从绝对路径中获取名字,从最后的闪lash、 j和roid中排出。
原标题:Obtain name from absolute path, substring from last slash, java android

我想摘取一条绝对道路的名称。 如果我有价值/mnt/sdcard/Videos/Videoname的画面,我就想节省一个带有价值视频名称的画面。

扼杀正在发生变化,我可以事先获得鞭.的数量。 我怎么能够从最后的争 the中分出一线?

/mnt/sdcard/Videos/Videoname -> Videnoname

问题回答

页: 1 文件:

归还这一抽象道路名称所标明的档案或目录名称。 这只是姓名顺序上的最后名字。 如果路名的顺序是空的,那么空洞就会回去。

例:

String name = new File("/mnt/sdcard/Videos/Videoname").getName();

如果您来自“File”物体,你可以采用以下方法:

String fileName = myFile.getName();

如果你从简单的角度来看待,你可以使用。

String fileName = myString.substring(myString.lastIndexOf("/")+1);
String path = "/mnt/sdcard/Videos/Videoname"; // Your path

String fileName = new File(path).getName(); // you file name

最容易的方式

String path ="AnyDirectory/subFolder/last.htm";
int pos = path.lastIndexOf("/") + 1;

path.substring(pos, path.length()-pos);

现在,你在路上是最后的。

但是,如果再作一些研究,以下法典则发挥作用......

String[] Tokens = stringPath.split("\\");

你们需要两次逃脱“”。

string a = "/foo/bar/target";
string words = a.Split("/")
string target = words[words.length-1]




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签