Java read binary file to Nodejs save __js

Source: Internet
Author: User

Java:

Package Com.iofamily.app;

Import Java.io.File;
Import Com.iofamily.util.FileUtils;

/**
 * @author lmiky
 * @date 2013-11-7/public
class Test {

	/**
	 * bytes converted to 16
	 * @author lmiky< c10/>* @date 2014-5-14
	 * @param src
	 * @return
	 *
	/public static String bytestohexstring (byte[] src) {
		StringBuilder StringBuilder = new StringBuilder ("");
		if (src = null | | src.length <= 0) {return
			null;
		}
		for (int i = 0; i < src.length i++) {
			int v = src[i] & 0xFF;
			String HV = integer.tohexstring (v);
			if (Hv.length () < 2) {
				stringbuilder.append (0);
			}
			Stringbuilder.append (HV);
		}
		return stringbuilder.tostring ();
	}

	public static void Main (string[] args) throws Exception {
		String sourcefile = "d:/test.jpg";
		File File = new file (sourcefile);
		byte[] bytes = fileutils.readfile (file);
		String hexstr = bytestohexstring (bytes);
		System.out.println (HEXSTR);
	}


Nodejs:

var utils = require ('./utils ');
var fs = require (' FS ');

var fileUtils = module.exports;

/**
 * Convert file binary data
 to file * @param filebyteshex read the file as 2 data into the 16 string
 * @param fileName
 * @param CB
 * *
fileutils.parsebytetofile = function (filebyteshex, filename, cb) {
	fs.writefile (filename, new Buffer ( Filebyteshex, ' hex '), function (err) {
		utils.invokecallback (CB, ERR);}
	);



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.