-1

I have a problem. I have some file without extension and I need discover the extension. How can I do that? I think the only way is to read the file, but i don't know how I can understand the extension. Thanks

user3541711
  • 95
  • 2
  • 8

4 Answers4

1

To probe the content of a File you could use the nio Java API and the method probeContentType

nuno
  • 1,771
  • 1
  • 19
  • 48
0

If your file has no extension (as you said) you cannot read the extension, because it is not present.

You could read the start of the file and look for some indicators of the content. E.g. most .pdf files start with %PDF-1.5 (or a different version number) in the content.

Simulant
  • 19,190
  • 8
  • 63
  • 98
0

I think that the only way is read the magic number of the file...how?

Check this thread Reading the header of a file in java

Hope that help you!

Community
  • 1
  • 1
appersiano
  • 2,670
  • 22
  • 42
0

Without extension, it's tough to find the format (but it's possible).

Even Windows asks you What to do when you click on Open With.. on a file without extension.

K139
  • 3,654
  • 13
  • 17