public static void main(String[] args) {
demo7("E:\\知乎.jpg");
demo7("D:\\知乎.jpg");
}
private static void demo7(String filesPath) {
//可以利用split分割,将最后一个元素输出,但是需要四个"\"
String[] split = filesPath.split("\\\\");
System.out.println(split[split.length - 1]);
String
//利用lastIndexOf()方法来实现
fileName=filesPath.substring(filesPath.lastIndexOf("\\")+1);
System.out.println(fileName);
/* //1.时间戳:获得当前时间纳秒数 fileName=System.currentTimeMillis()+"_"+fileName;
System.out.println(fileName);*/
//2.随机的java.util.UUID
fileName=UUID.randomUUID().toString()+"_"+fileName;
System.out.println(fileName);
}
标签:filesPath,唯一性,String,System,fileName,当有,split,文件名称,out
From: https://www.cnblogs.com/Liku-java/p/16943173.html