How can I distinguish between text file and binary file after I read a file onto my servlet?

Luigi Viggiano

Reading it and checking the file's content: if it contains only chars in [a..z, A..Z, 0..9] and punctuation marks, it's a text file; viceversa, if it contains extended chars it isn't.

Another good way, is to do it statistically: if it contains 85% (for example) of alphanumerical chars, probably it's a text file. You can take statistics on the first buffer read from the file to speed up checking.

To recognize binary data format check also How do I know that a particular file is in binary or text format without relying on the extention of a file?.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact