byte數組轉16進制 輸出到文件


 

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

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM