954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Accessing files

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

Thanks in advance

vex
Newbie Poster
22 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

extensions maybe?

Binary is suppose to be .dat
Test is .txt or .text

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

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.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

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

vex
Newbie Poster
22 posts since Apr 2005
Reputation Points: 10
Solved Threads: 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.

vex
Newbie Poster
22 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
 

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

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You