Here you can find the source of fileWrite(String path, int format, String content, Object bytesObj)
public static int fileWrite(String path, int format, String content, Object bytesObj)
//package com.java2s; //License from project: Open Source License import java.io.FileOutputStream; public class Main { public static int fileWrite(String path, int format, String content, Object bytesObj) { byte[] bytes = null; try {//from ww w . ja v a2 s .c om switch (format) { case 0: bytes = (byte[]) bytesObj; break; case 1: // UTF8 bytes = content.getBytes("UTF-8"); break; case 2: // UTF8 w/ BOM bytes = content.getBytes("UTF-8"); byte[] tbytes = new byte[bytes.length + 3]; System.arraycopy(bytes, 0, tbytes, 3, bytes.length); bytes = tbytes; bytes[0] = (byte) 239; bytes[1] = (byte) 187; bytes[2] = (byte) 191; break; case 3: // UTF16 bytes = content.getBytes("UTF-16LE"); break; case 4: // UTF32 bytes = content.getBytes("UTF-32LE"); break; case 5: bytes = content.getBytes("ISO-8859-1"); break; default: return 3; } } catch (java.io.UnsupportedEncodingException uee) { throw new RuntimeException("Unsupported encoding exception in fileWrite"); } FileOutputStream stream = null; try { stream = new FileOutputStream(path); stream.write(bytes); return 0; } catch (java.io.IOException ioe) { return 1; } finally { if (stream != null) { try { stream.close(); } catch (java.io.IOException ioe) { return 1; } } } } }