String inputFilePath = "E:\\tmp\\test\\source\\video\\a.flv";
/0./获取文件路径,有后缀,eg:获取E:\tmp\test\source\video\a.flv
inputFilePath = inputFilePath.trim();
String fileName = inputFilePath.substring(inputFilePath.lastIndexOf("/")+1);
System.out.println("fileName = " + fileName);
//1.获取文件路径,无后缀,eg:获取E:\tmp\test\source\video\a
String filename = inputFilePath;
String caselsh = filename.substring(0,filename.lastIndexOf("."));
System.out.println(caselsh);
//2.获取文件名,有后缀,eg:获取a.flv
String filePath1 = inputFilePath;
String fileName1 = filePath1.substring(filePath1.lastIndexOf("\\")+1);
System.out.println(fileName1);
//3.获取文件名,无后缀,eg:获取a
String filePath = inputFilePath;
String fileName2 = filePath.substring(filePath.lastIndexOf("\\")+1);
String name = fileName2.substring(0,fileName2.lastIndexOf("."));
System.out.println(name);
//4.获取文件名的后缀,eg:获取flv
String filePath3 = inputFilePath;
String fileName3 = filePath.substring(filePath3.lastIndexOf("\\")+1);
String extension=fileName3.substring(fileName3.lastIndexOf(".")+1);
System.out.println(extension);
获取文件的路径或文件名
最新推荐文章于 2023-09-12 23:15:33 发布