Java 将字节数组转换为可读字符串:ASCII 码转换
try {\n\t\tinputStream = new FileInputStream("C:\Users\mko4\Desktop\PK");;\n\t\tint fileByteSize = inputStream.available();\n\t\t// Log.i(TAG, "bytesize is " + fileByteSize);\n\t\tif (fileByteSize > 0) {\n\t\t\tbyte[] bytes = new byte[fileByteSize];\n\t\t\tinputStream.read(bytes);\n\t\t\tdecodeSignatureInfo(bytes);\n\t\t\t//releaseSignature = Arrays.toString(bytes);\n\t\t\tStringBuilder builder = new StringBuilder();\n\t\t\tfor (byte b : bytes) {\n\t\t\t\tString hex = String.format("%02x, ", b);\n\t\t\t\tbuilder.append(hex);\n\t\t\t}\n\t\t\treleaseSignature = builder.toString();\n\t\t}\n\t}将bytes的每一位按ascii码,转为可读的符号内容:将bytes的每一位按ascii码转为可读的符号,可以使用以下代码:\n\njava\nStringBuilder builder = new StringBuilder();\nfor (byte b : bytes) {\n\tchar c = (char) b;\n\tbuilder.append(c);\n}\nString readableBytes = builder.toString();\n\n\n这样,readableBytes就是将bytes数组中的每一位按ascii码转换为可读的符号后的字符串。
原文地址: https://www.cveoy.top/t/topic/qeY6 著作权归作者所有。请勿转载和采集!