Here you can find the source of detectFileType(String location)
Parameter | Description |
---|---|
location | the location of the file to detect the file type for. |
Parameter | Description |
---|---|
IOException | if an I/O error occurs. |
public static String detectFileType(String location) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { /**/*from w w w .j ava2s . c o m*/ * This function detects the file type of a file at the given location. * * @param location * the location of the file to detect the file type for. * @return a string indicating the file type of the file. * @throws IOException * if an I/O error occurs. */ public static String detectFileType(String location) throws IOException { String sanitizedLocation = location.replaceFirst("^/(.:/)", "$1"); Path filePath = Paths.get(sanitizedLocation); return Files.probeContentType(filePath); } }