从绝对路径获得名,从去年的斜线串,JAVA机器人斜线、机器人、绝对路径、从去年

2023-09-07 15:20:05 作者:A逼C迪E爱抚鸡

我要提取的绝对路径名。如果我有一个值的/ mnt / SD卡/视频/ Videoname一个字符串,我要保存的值Videoname的字符串。

该字符串正在改变,我无法获得previously斜线的数量。我怎么能在最后一个斜线分割子?

  

到/ mnt / SD卡/视频/ Videoname - > Videnoname

解决方案

您应该通过的 文件 API。从File.getName()文档:

  

返回由此抽象路径名表示的文件或目录的名称。这仅仅是在路径的名称序列中的最后名称。如果路径名的名称序列为空,则返回空字符串。

例如:

 字符串名称=新的文件(到/ mnt / SD卡/视频/ Videoname)的getName(); 

礼舍领跑HR SaaS行业,智能化 无纸化 数据化企服时代强势来袭

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 the File.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();