Skip to main content

APIzation: Replication Package

[Q#26019132][A#26019206] How to split a file path to get the file name?

https://stackoverflow.com/q/26019132

I have this string in my Android Application: I need manipulate the string and to split the string for this output: I need always take the last element of the string. How to this output in java? I would greatly appreciate any help you can give me in working this problem.

Answer

https://stackoverflow.com/a/26019206

one another possibility:

APIzation

String lStr = "/storage/emulated/0/temp.jpg";
lStr = lStr.substring(lStr.lastIndexOf("/"));
System.out.println(lStr);
package com.stackoverflow.api;

public class Human26019206 {

  public static String getFileNameFromPath(String lStr) {
    lStr = lStr.substring((lStr.lastIndexOf("/")));
    return lStr;
  }
}

package com.stackoverflow.api;

/**
 * How to split a file path to get the file name?
 *
 * @author APIzator
 * @see <a href="https://stackoverflow.com/a/26019206">https://stackoverflow.com/a/26019206</a>
 */
public class APIzator26019206 {

  public static String splitPath(String lStr) throws Exception {
    lStr = lStr.substring(lStr.lastIndexOf("/"));
    return lStr;
  }
}