Java CharSequenceInputStream-class And Method Code Example

Here is an example of how to use the CharSequenceInputStream class from the Apache Commons IO library in Java:


public class MyClass {
    public static void main(String[] args) throws IOException {
        CharSequenceInputStream inputStream = new CharSequenceInputStream("This is an example text", "UTF-8");
        int nextByte =;
        while (nextByte != -1) {
            // do something with the byte
            nextByte =;

In this example, CharSequenceInputStream is wrapping a CharSequence that contains the string "This is an example text".

It converts the CharSequence to a byte array using the specified encoding.

The CharSequenceInputStream is used in the same way as any other InputStream, in this case it reads a byte at a time until the end of the input is reached.

Please note that this is a simple example, in real-world usage, you might want to do more complex processing on the bytes before returning them.