从byte [] android转换后,Mp3文件没有播放

Bik*_*ash 7 base64 mp3 android encode decode

我只是将一个mp3文件转换为字节代码并将该字节代码重新转换为mp3并保存到sdcard,所有过程都成功进行但问题是保存的mp3文件没有在设备mp3播放器上播放它显示不支持的格式.

我的下面的代码有什么问题

  private void convertBytesToFile(byte[] bytearray) {


    byte[] bytes = bytearray;

    String encoded = Base64.encodeToString(bytes, 0);
  //  Utilities.log("~~~~~~~~ Encoded: ", encoded);

    byte[] decoded = Base64.decode(encoded, 0);
    //Utilities.log("~~~~~~~~ Decoded: ", Arrays.toString(decoded));

    try
    {
        File file2 = new File(Environment.getExternalStorageDirectory() + "/hello-2.mp3");
        FileOutputStream os = new FileOutputStream(file2, true);

        os.write(decoded);
        os.close();
    }
    catch (Exception e)
    {
        Toast.makeText(this, "Somthing wrong", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }

}
Run Code Online (Sandbox Code Playgroud)

或者我遗失的任何东西.请帮朋友.

God*_*win 0

为什么要将 mp3 转换为 Base64?如果你想保存到SD卡请执行以下代码

private void convertBytesToFile(byte[] bytearray) {

    FileOutputStream fos = new FileOutputStream(Environment.getExternalStorageDirectory() + "/hello-2.mp3");
    fos.write(byteArray);
    fos.close()
    }
Run Code Online (Sandbox Code Playgroud)