Hi all, Is it possible for me to know whether a file is an ascii file or a binary file using any Java method. My intention is to display the contents of the file if the file is a text file (whether it is .txt, .java, .html etc) and not do anything if it is a binary file (.bmp, .gif, .class, .doc etc.) Thank you Sathish
Sorry to be posting a reply to my own question. But I found this answer to the question at a different site. I guess somebody could corroborate this or give me another answer. { There is no easy way to tell since ASCII characters are binary. Depending upon how you read the file determines how you treat the data. For instance, the text "CAFE" if read as an int is the value 1128351301. Since Java also deals with Unicode and not just ASCII, you get to worry about 8-bit vs. 16-bit characters, too. } Thanks Sathish
Thanks for sharing this Satish, but pleas note that The Java Ranch has a naming policy, described here and "SathishVJ" is not a valid name. Please choose one which meets the requirements. Thanks.
hi well if you'r file has an extension then u can use file filter to filter the files as u need.list() and listFiles() methods are oevrloaded to versions which can filter the files using .extensions.is using list() extend from FilenameFilter else if using listfile() extend from FileFilter.right these both are interfaces with an abstract method accept().list and listFile() call this accept () method.hope you're doubt is cleared if not please feel free to ask me again. bye anuj khanna denedal@hotmail.com
And then the flying monkeys attacked. My only defense was this tiny ad:
Gift giving made easy with the permaculture playing cards