0

Is there a simple way to test wether or not a file is binary or text???

Thanks in advance

3
Contributors
5
Replies
6
Views
11 Years
Discussion Span
Last Post by server_crash
0

Every file is binary data by definition.
A text file contains only data in the specific code page/character set you're using. Which that is would depend on your locale.

You'd have to attempt to read the file and throw an exception if you encounter data that doesn't map to text in your expected codepage.

0

Thanks for the reply

I am also using JFileChooser to save files. When the dialog opens I can type the filename I want to save as. If I do not type a extension it will not add one. Is there an option for setting a default extension. ie, If I save a Word document there is no need to type the .doc

Thanks again

0

Every file is binary data by definition.
A text file contains only data in the specific code page/character set you're using. Which that is would depend on your locale.

You'd have to attempt to read the file and throw an exception if you encounter data that doesn't map to text in your expected codepage.

I guess I will just check the extension. Sounds much easier. I will only be dealing with txt and dat files.

Thanks for the input though.

0

Use a file filter. I think there's an accept() method that you can provide a default extension in, but not sure.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.