How to check the extension of a Java 7 Path

前端 未结 4 1162
温柔的废话
温柔的废话 2020-12-08 03:23

I\'d like to check if a Path (introduced in Java 7) ends with a certain extension. I tried the endsWith() method like so:

Path path = Paths.get         


        
4条回答
  •  北海茫月
    2020-12-08 04:15

    There is no way to do this directly on the Path object itself.

    There are two options I can see:

    1. Convert the Path to a File and call endsWith on the String returned by File.getName()
    2. Call toString on the Path and call endsWith on that String.

提交回复
热议问题