package com.logicbig.example.files;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class ProbeContentTypeExample {
public static void main(String... args) throws IOException {
Path path = Files.createTempFile("test-file", ".txt");
System.out.println("Probe Content Type for file: " + path);
String type = Files.probeContentType(path);
System.out.println("File Content type: " + type);
path = Files.createTempFile("test-file", ".html");
System.out.println("Probe Content Type for file: " + path);
type = Files.probeContentType(path);
System.out.println("File Content type: " + type);
}
}
Output
Probe Content Type for file: C:\Users\Joe\AppData\Local\Temp\test-file5673809405755370146.txt
File Content type: text/plain
Probe Content Type for file: C:\Users\Joe\AppData\Local\Temp\test-file14702966924326758655.html
File Content type: text/html