Java获取文件名、文件类型(文件后缀名)

public class Test {

  public static void main(String[] args) {

    String fileName = "upload/20221125/20221125563750.pdf";
    String filePath = fileName.replace("/", "\");
    String oldName = filePath.substring(filePath.lastIndexOf("\") + 1);
    System.out.println(oldName);
  }
}

 

你可能感兴趣的