作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将字节数组转换为字符串,以便能够查看此 vector/数组并分析这些字节的组织方式。
我使用下面的代码来做到这一点:
byte[] bytes = bos.toByteArray();
String msgDecode = new String(bytes); // trying to convert byte in String
System.out.println("Vetor de bytes [" + msgDecode + "]"); // Showing it
但是它不起作用。为什么上面的代码不起作用?
值得一提的是,字节数组是根据此处的其他代码构造的:
String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+UUID.randomUUID().toString()+"audio_record.3gp";
public byte[] convert(String path) throws IOException {
FileInputStream fis = new FileInputStream(path);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
for (int readNum; (readNum = fis.read(b)) != -1; ) {
bos.write(b, 0, readNum);
}
byte[] bytes = bos.toByteArray();
return bytes;
}
总体思路是使用智能手机录制音频并将该音频文件转换为字节数组。该字符串路径是录制后保存音频的路径。然后我使用这个路径(代表音频文件)并根据上面的代码将其转换为字节数组。
您可以在这里找到并帮助我的更多信息:How to solve this error: Android resource linking failed?
最佳答案
如果你想查看字节值,可以使用如下:
Log.d("TAG", Arrays.toString(bytes));
关于java - 如何将字节数组转换为字符串以便将其打印到控制台上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59752616/
我正在开发一个在 VS 社区 2017 中开发并使用 IIS Express 10 的 .net Core MVVC 项目,我遇到了 TempData 无法在我开发的 3 台计算机中的两台上运行的问题
我是一名优秀的程序员,十分优秀!