Binary encoding

Advertisement
Hi , I am writing an ascii file, how can i binary encode it.
Thanks.
Advertisement

Replay

Not sure if this is what you are looking for; but this is how I usually create real ascii files. (J2SDK 1.4)
- Chris
import java.io.*;
import java.nio.charset.*;
import java.nio.*;
public class Main
  public static void main(String[] args)
    CharsetEncoder asciiEncoder = Charset.forName("US-ASCII").newEncoder();
    String messageToWrite = "Hello World\r\n";
    try
      FileOutputStream os = new FileOutputStream("c:/test.txt");
      os.write(
          asciiEncoder.encode(CharBuffer.wrap(messageToWrite)).array()
      os.close();
    catch (IOException ex)
      ex.printStackTrace();