Here you can find the source of writeToFile(String path, ByteOrder byteOrder)
public static void writeToFile(String path, ByteOrder byteOrder)
//package com.java2s; //License from project: Apache License import java.io.*; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { public static void writeToFile(String path, ByteOrder byteOrder) { String fileName = "My new STL"; File file = new File(path); DataOutputStream output = null; try {/*from w w w.j a va 2s.c o m*/ output = new DataOutputStream(new FileOutputStream(path)); byte[] fileNameByteArray = fileName.getBytes(); ByteBuffer buffer = ByteBuffer.allocate(500); buffer.order(byteOrder); byte[] fillerArray = new byte[80]; System.arraycopy(fileNameByteArray, 0, fillerArray, 0, fileNameByteArray.length); buffer.put(fillerArray); buffer.putInt(1); //Normal buffer.putFloat(0.0f); buffer.putFloat(-100.0f); buffer.putFloat(0.0f); //P1 buffer.putFloat(0.0f); buffer.putFloat(0.0f); buffer.putFloat(10.0f); //P2 buffer.putFloat(10.0f); buffer.putFloat(0.0f); buffer.putFloat(0.0f); //P3 buffer.putFloat(0.0f); buffer.putFloat(0.0f); buffer.putFloat(0.0f); buffer.putShort(((short) 0)); byte[] bytes = buffer.array(); output.write(bytes); output.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }