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);}
);