For example, the obtained file path is C:/Documents and Settings/Leeo/My Documents documents/logo.gif.
Now we want to get the image name logo.gif. We know that the Backslash "/" is an escape character, so we cannot directly
String temp [] = filepath. Split ("/"); // The value of filepath is the file path above.
To split the file path.
/*
* In Java, // indicates a/, while in RegEx, // also indicates /,
* When /// is resolved to RegEx //
**/
String temp [] = filepath. Split ("////");
In Linux
System. getproperty ("file. separator ","//")
The output is "/", while the output is "/" in windows. Therefore, you must be compatible with the two.
String temp [] = filepath. replaceall ("//", "/"). Split ("/");
Obtain the complete file nameCodeAs follows:
String temp [] = filepath. replaceall ("//", "/"). Split ("/");
String filename = ""
If (temp. length> 1 ){
Filename = temp [temp. Length-1];
}