简体   繁体   English

是否可以使用文件的内容类型来确定Java中的文件类型?

[英]Is it possible to use the content-type of a file to determine its filetype in Java?

If so, how can I do that? 如果是这样,我该怎么做?

I'm trying to write a method that takes a content-type and returns whether it is a JSON file or not. 我正在尝试编写一种采用内容类型并返回是否为JSON文件的方法。

Here is a function which takes in a content-type string from an HTTP request and returns TRUE if the content-type was a JSON type or FALSE if it wasn't. 这是一个函数,该函数从HTTP请求中获取内容类型字符串,如果内容类型为JSON类型,则返回TRUE,否则返回FALSE。

public static boolean isJsonContentType(String contentType) {
    return (contentType.equals("application/json"));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM