byte数组转16进制 输出到文件

时间:2021-06-12 06:23:57
try {

	File file = new File(Environment.getExternalStorageDirectory(),"shuju2");
if(!file.exists()){
file.createNewFile();
}
FileWriter fw = new FileWriter(file);
BufferedWriter out = new BufferedWriter(fw);
out.write(toHexString1(bytes));
out.close();
} catch (IOException e) {
e.printStackTrace();
} public static String toHexString1(byte[] b){
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < b.length; ++i){
buffer.append(toHexString1(b[i]));
}
return buffer.toString();
} public static String toHexString1(byte b){
String s = Integer.toHexString(b & 0xFF);
if (s.length() == 1){
return "0" + s;
}else{
return s;
}
}