A string array of bytes written to the file

    /**
     * Java,把字符串字节数组写入文件
     * @param byt
     * @throws Exception
     */
    private static void byte2File(byte[] byt) throws Exception {
        if (null == byt) {
            return;
        }
        String targetFile = "C:\\Users\\fileTestTarget.txt";
        File file = new File(targetFile);
        OutputStream output = new FileOutputStream(file);
        BufferedOutputStream out = new BufferedOutputStream(output);
        InputStream in = new ByteArrayInputStream(byt);
        byte[] buff = new byte[1024];
        int len = 0;
        while ((len = in.read(buff)) != -1) {
            out.write(buff, 0, len);
        }
        in.close();
        out.close();
        System.out.println("---- done ----");
    }

       If the argument is a string "HelloWorld" byte array, it can be written HellowWorld fileTestTarget.txt.

Guess you like

Origin www.cnblogs.com/east7/p/12208116.html