-4

I am trying to parse files with different extension types in my Java program. I just got a strange file which has a unique file format as below.

20121126.033111.vikeng8.28088

I am not sure what is the extension of this particular file. Windows shows type as 28088 File. I think its some kind of a text file. I was not able to find any further information from Google. I can open it in Notepad++ and Notepad.

How can I determine this file extension type from Java? What would be the extension in general for these kind of files?

Further, I need to open this file and read some information from it. Any help would be very useful as i am seeing this kind of strange file for the first time.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
vikeng21
  • 543
  • 8
  • 28

2 Answers2

1

The extension doesn't necessarily mean anything - for example, putting a .txt extension on a .jpg file doesn't mean it is no longer a .jpg - the file type is generally determined by the contents; the extension is supposed to be a clue to what the contents are.

Regards to your question - the extension on this file is indeed .28088 - though that gives no indication at all of the contents. Java wouldn't be able to tell you anything different.

Krease
  • 15,805
  • 8
  • 54
  • 86
  • Thanks Chris. In my Java code i am determining extension types of files and doing some processing. Example: .zip(some process), .gz(some process), .txt(Some process) etc etc. How do i handle the above kind of particular extension types using Java. I cannot check for numbers right which would be practically impossible as numbers will vary every time. I hope you got my problem correctly. – vikeng21 Nov 26 '12 at 18:33
1

File extensions are not reliable.

That is just the Windows version of doing things, but obviously file names can be changed. So it is up to the user to give the files a sensible name, unfortunately.

Unix has libraries for detecting the type of a file. For example the command file example.cc will output something like C++ source, ASCII text, with very long lines.

I'd assume it is a single email message or something like this, which you can then treat as an mbox file.

Nevertheless, if you aren't sure about the file extension, assume it is incorrect and perform proper file type detection.

See e.g.: How to reliably detect file types?

Community
  • 1
  • 1
Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194