Results 1 to 7 of 7
- 06-21-2011, 07:55 PM #1
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
way to catch if file is simple text based
hello,
I'm filtering files.
I'm looking for a way to detect if a file is simple text based(not encoded).
Of course I could define all the extensions, but is there a quick way to see if file is simple text(for e.g.: *.php) or encoded (for e.g.: *.exe) ?
Thanks in advance!
- 06-21-2011, 08:09 PM #2
I believe I did something similar to what you're asking about earlier today. However I did mine in Swing. I'm pretty sure it belongs to IO so you should be able to use it in non-swing applications.
Using a buffered reader I opened up a selected file. Using the file information it collected I usedYou could try something similar to accomplish that. Reading through a folder, directory or other collection of files may require a little bit more than this seeing as mine asked you to input the file location.Java Code:if(file.getAbsolutePath().contains(".txt")){//Code}- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 06-21-2011, 08:11 PM #3
Read it and check that all bytes/chars read are text or controls like tab and newlineway to detect if a file is simple text based
Not all files have extensions.
- 06-21-2011, 08:17 PM #4
I think he's trying to distinguish between files that do have extensions, at least that's what I got from it.
- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 06-21-2011, 09:09 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
That'd only catch English/American text, i.e. ASCII representable text. Any text outside of that (limited) range would fail that test. No need to worry though, because the good old 'file' Unix utility would fail as well ;-) There is no one-size-fits-all cheap test to classify a file base on its contents nor on its name nor on its name extension.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-21-2011, 10:15 PM #6
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
hmmm, so how do famous programs(like searching in files) handle reading files and excluding executables?
Or it simply can not be done using Java?
- 06-21-2011, 10:18 PM #7
Similar Threads
-
My Try Catch block isn't catching the right value from a file.
By theBurgh22 in forum New To JavaReplies: 11Last Post: 12-06-2010, 05:00 PM -
Text based games help
By mustachMan in forum New To JavaReplies: 0Last Post: 12-04-2009, 01:11 AM -
a simple code (cldc or midp) to write a text file ouside of the application package
By sina in forum CLDC and MIDPReplies: 3Last Post: 12-12-2008, 12:12 PM -
printing simple text as text on printer
By Nicholas Jordan in forum Advanced JavaReplies: 0Last Post: 12-01-2008, 01:42 AM -
creating a text based game
By Phobos0001 in forum New To JavaReplies: 1Last Post: 02-12-2008, 04:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks