DataOutputStream.writeChars(String s) has the following syntax.
public final void writeChars(String s) throws IOException
In the following code shows how to use DataOutputStream.writeChars(String s) method.
/* www .j a va2s . co m*/ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static void main(String[] args) throws IOException { String s = "Hello from java2s.com!!"; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); dos.writeChars(s); dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { char c = dis.readChar(); System.out.print(c); } } }