Identifying file type in Java

前端 未结 6 1187
盖世英雄少女心
盖世英雄少女心 2020-12-08 23:24

Please help me to find out the type of the file which is being uploaded. I wanted to distinguish between excel type and csv.

MIMEType returns same for both of thes

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 23:55

    The CSV will start with text and the excel type is most likely binary.

    However the simplest approach is to try to load the excel document using POI. If this fails try to load the file as a CSV, if that fails its possibly neither type.

提交回复
热议问题