Finding the file extension before reading
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ragu_varan
Posted On:   Tuesday, August 8, 2006 01:46 AM

I hava zip file like " my.zip " in my local System
I am changing this file extension to txt (eg . my.txt );
Now i want to read this file , but before reading that file, i have to make sure really it is a text file( and want to know that this file extension is changed),
Are there any option in File class or any other classes.
(i.e. I want to know there is any option to check that the file is not a text file ,but the extension is changed to " txt ")

Re: Finding the file extension before reading

Posted By:   Stephen_Ostermiller  
Posted On:   Sunday, August 27, 2006 04:33 PM

The Unix "file" command examines the contents of the file and makes a guess as to the type of file that it actually is. If you are running on a unix system, you would be able to call the program using runtime exec.


Otherwise, the file website has the source code. You might be able to translate it into Java.

Re: Finding the file extension before reading

Posted By:   WarnerJan_Veldhuis  
Posted On:   Tuesday, August 8, 2006 04:00 AM

As far as Java is concearned, a zipfile and a textfile are just files with bytes in them. They just have a different meaning to different programs. Even when you have a text file, there is still the issue of the encoding, ie ASCII, EBCDIC, UTF8, UTF16, UTF32, the works... I would suggest you treat the file as what the extension tells it tobe, and just handle or throw any exception if things aren't going the way they are supposed to go...
About | Sitemap | Contact