Splitting filenames using system file separator symbol

前端 未结 4 1495
傲寒
傲寒 2021-01-01 15:31

I have a complete file path and I want to get the file name.

I am using the following instruction:

String[] splittedFileName = fileName.split(System.         


        
4条回答
  •  被撕碎了的回忆
    2021-01-01 15:55

    Another simpler way could be to do

    File f = new File(path);
    String fileName = f.getName();
    

    I believe this will work provided the paths are compatible with the platform, i.e. not sure if path "c:\file.txt" will work on Linux or not.

提交回复
热议问题