截取倒數第二個"/"之後的字符串
String path="/home/henry/Desktop/1.txt";
//獲得"Desktop/1.txt",並且不需要前面的"/"
String oo=path.substring(path.lastIndexOf("/",path.lastIndexOf("/")-1)+1);
//"+1"代表在定位時往後取一位,即去掉"/"
//"-1"代表以"/"字符定位的位置向前取一位
//從path.lastIndexOf("/")-1位置開始向前尋找倒數第二個"/"的位置
System.out.println(oo);
運行結果