Results 1 to 5 of 5
Thread: Binary and ASCII
- 01-10-2010, 05:50 AM #1
- 01-10-2010, 05:55 AM #2
well... ASCII is binary too :D I don't know of a way to auto-detect, since many plain binary sequences do represent real ascii characters, it'd be hard to tell just by looking at the file (with java, not your eyes).
- 01-10-2010, 07:05 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Now posted at New To Java - Binary or ASCII (Sun forums)
@OP: It would be good to actually tell the rest of us (and link) when the discussion is going on at other places.
- 01-10-2010, 08:41 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,404
- Blog Entries
- 7
- Rep Power
- 17
- 01-10-2010, 06:31 PM #5
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
I encountered this issue, while working with files
that contained words from foreign alphabets so I used this code:
Java Code:import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CharacterCodingException; /** Test if char is ASCII or not */ public class TestAscii { public static void main (String args[]) throws Exception { // this String throws an Exception, it contains an accented letter String test = "Réal"; // this String is OK //String test = "Real"; byte bytearray [] = test.getBytes(); System.out.println("Test string : " + test); CharsetDecoder d = Charset.forName("US-ASCII").newDecoder(); try { CharBuffer r = d.decode(ByteBuffer.wrap(bytearray)); r.toString(); } catch(CharacterCodingException e) { System.out.println("only regular ASCII characters please!"); // interrupt the processing throw new Exception(e); } System.out.println("Ok, it's ASCII only!"); } }
Similar Threads
-
Help with ASCII Drawing--For loops--if/else
By alice.li.mastriano in forum New To JavaReplies: 1Last Post: 09-13-2009, 12:31 AM -
Getting ascii from a String
By ali_sakar in forum New To JavaReplies: 1Last Post: 03-07-2009, 10:11 AM -
Another ascii question....
By akira220984 in forum New To JavaReplies: 5Last Post: 02-20-2009, 01:38 AM -
I need help with ascii characters
By Grandon in forum EclipseReplies: 17Last Post: 11-08-2008, 02:12 AM -
Ascii code.........
By Somitesh Chakraborty in forum New To JavaReplies: 6Last Post: 11-04-2008, 05:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks