Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    public static final String ENCODING = "UTF-8";

    public static byte[] charArrayToByteArray(char[] buffer) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            OutputStreamWriter out = new OutputStreamWriter(baos, ENCODING);
            Reader reader = new CharArrayReader(buffer);
            for (int ch; (ch = reader.read()) != -1;) {
                out.write(ch);
            }
            return baos.toByteArray();
        } catch (Exception ex) {
            return null;
        }
    }
}