编程知识 cdmana.com

Java: org.apache.commons . io.FilenameUtils Get the file name and extension

rely on

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.4</version>
</dependency>

FilenameUtils Examples of use


import org.apache.commons.io.FilenameUtils;

public class IODemo {
    
    public static void main(String[] args) {
    
        String filename = "/root/name.txt";

        System.out.println(FilenameUtils.getName(filename));
        // name.txt

        System.out.println(FilenameUtils.getBaseName(filename));
        // name

        System.out.println(FilenameUtils.getExtension(filename));
        // txt

    }
}

版权声明
本文为[Peng Shiyu]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224171911702n.html

Scroll to Top