Is there a simple way to test wether or not a file is binary or text???
Thanks in advance
extensions maybe?
Binary is suppose to be .dat
Test is .txt or .text
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.
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
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.
Use a file filter. I think there's an accept() method that you can provide a default extension in, but not sure.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.