Tagged
#Java NIO
1 post
-
Get File Extension and MIME Type in Java Without Third-Party Libraries
You don't need Apache Commons or Guava to pull the extension off a filename or detect its MIME type. Java 7's NIO and Java 8's Optional / Stream API are enough — and the code you end up with is short, null-safe, and easy to paste into any project. This article walks through both recipes, then covers the Paths.get vs Path.of split and the cross-platform quirks of Files.probeContentType.