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[] convertIntToByteArray(int my_int) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(bos);
        dos.writeInt(my_int);
        dos.close();
        byte[] int_bytes = bos.toByteArray();
        bos.close();
        return int_bytes;
    }
}