Split string with dot as delimiter

后端 未结 13 2467
死守一世寂寞
死守一世寂寞 2020-11-22 11:14

I am wondering if I am going about splitting a string on a . the right way? My code is:

String[] fn = filename.split(\".\");
return fn[0];
         


        
13条回答
  •  没有蜡笔的小新
    2020-11-22 11:57

    Using ApacheCommons it's simplest:

    File file = ...
    FilenameUtils.getBaseName(file.getName());
    

    Note, it also extracts a filename from full path.

提交回复
热议问题