0

こんにちはみんな私はアセットフォルダにオーディオファイルを持っています、そして私は同じファイルをSDカードに保存する必要があります。

これを達成する方法。

以下は私がファイルを保存するために使用しているコードです

String filename = "filename.txt";
File file = new File(Environment.getExternalStorageDirectory(), filename);
FileOutputStream fos;
byte[] data = new String("data to write to file").getBytes();
try {
    fos = new FileOutputStream(file);
    fos.write(data);
    fos.flush();
    fos.close();
} catch (FileNotFoundException e) {
    // handle exception
} catch (IOException e) {
    // handle exception
}

助けてください

4

1 に答える 1

2

これを試して

AssetManager mngr = getAssets();
InputStream path = mngr.open("music/music1.mp3"); 

                    BufferedInputStream bis = new BufferedInputStream(path,1024);

                    //get the bytes one by one
                    int current = 0;

                    while ((current = bis.read()) != -1) {

                        baf.append((byte) current);
                    }
}
byte[] bitmapdata  = baf.toByteArray();

バイト配列に変換した後、次のようにこれをsdcardにコピーします

File file = new File(Environment.getExternalStorageDirectory(), music1.mp3);
FileOutputStream fos;

try {
    fos = new FileOutputStream(file);
    fos.write(bitmapdata  );
    fos.flush();
    fos.close();
} catch (FileNotFoundException e) {
    // handle exception
} catch (IOException e) {
    // handle exception
}
于 2012-02-29T05:32:03.613 に答える