write Char via InputStream - Java java.io

Java examples for java.io:InputStream Read

Description

write Char via InputStream

Demo Code


//package com.java2s;

import java.io.IOException;

import java.io.OutputStream;

public class Main {
    private static void writeChar(char c, OutputStream os)
            throws IOException {
        os.write((c >>> 8) & 0xFF);
        os.write((c >>> 0) & 0xFF);
    }//w  ww  .j a  v  a  2  s. c  o  m

    public static void write(String s, OutputStream os) throws IOException {
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++)
            writeChar(chars[i], os);
        writeChar((char) 0, os);
    }
}

Related Tutorials