android - How to upload audio file to internal storage?
问题描述
So I have a button called, "Attach audio effect." That is where I will get the location of my file and once I click "add", the mp3 file is uploaded to my /files/audio/
Here is an image of my file location
Yes, it successfully inserted but the file seems to be empty based on the size which says, "0 Bytes"
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis;
try {
fis = new FileInputStream(new File(audioFxUri.getPath()));
byte[] buf = new byte[1024];
int n;
while (-1 != (n = fis.read(buf)))
baos.write(buf, 0, n);
} catch (Exception e) {
e.printStackTrace();
}
byte[] bbytes = baos.toByteArray();
//byte to file
File output = new File(getFilesDir() + "/audio",audioFxUri.getPath());
FileOutputStream fileoutputstream = null;
try {
fileoutputstream = new FileOutputStream(output);
fileoutputstream.write(bbytes);
fileoutputstream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
I've been stuck with this problem for almost a week now. Please help me! Thank you so much!
解决方案
推荐阅读
- jquery - 如何通过确认模式JQuery Flask传递选中的复选框列表
- javascript - 按钮单击不会显示内容
- python - 如何调用多个返回之一?
- laravel - Laravel 更新模型而不是保存新的
- python - 运行 OCR Python
- reactjs - 加载父状态数组时显示微调器
- r - 使用交叉验证时,有没有办法确保每个折叠以某种方式包含至少几个真实类的实例?
- cassandra - 每个切片的最大墓碑数过高的问题?
- office-ui-fabric - Office-ui-fabric-react 选择组在与文本字段相同的组件中时行为不正确
- excel - 我使用 INDEX 和 MATCH 与 excel 来返回我想要的值,但我可以让它在匹配中它必须匹配两组数据而不是一组?