Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.io.DataOutputStream;
import java.io.IOException;

public class Main {
    public static byte[] longToByteArray(long number) {
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            dos.writeLong(number);
            dos.flush();
            // lenth have to be 2 byte
            byte[] d = bos.toByteArray();
            dos.close();

            return d;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}