LoginSignup
8
7

More than 5 years have passed since last update.

ファイルからMimeTypeを取得する

Posted at

javax.activation.FileTypeMapを使うとこんな感じで取得可能。

import javax.activation.FileTypeMap;

import org.junit.Test;

public class MimeTypeTest {

    @Test
    public void test() {
        String filepath = "/tmp/test.gif";
        FileTypeMap filetypeMap = FileTypeMap.getDefaultFileTypeMap();
        String mimetype = filetypeMap.getContentType(filepath);
    }

}
8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7