Alternative to Files.probeContentType?

前端 未结 3 963
温柔的废话
温柔的废话 2021-01-01 09:35

In a web project, users upload their files, but when I receive them on the server, they are being stored as .tmp files rather than their original file extension (this is my

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-01 10:08

    This answer suggests using:

    InputStream is = new BufferedInputStream(new FileInputStream(file));
    mimeType = URLConnection.guessContentTypeFromStream(is);
    //...close stream
    

提交回复
热议问题