0
嗨,我需要將音樂文件保存到SD卡我試過使用下面的代碼只有文件夾在SD卡中創建的文件夾沒有音樂文件保存任何一個建議我在哪裏我做了錯誤...如何將音樂文件從原始文件夾保存到SD卡中android
FillesaveActivity.class:
public class FillesaveActivity extends Activity {
/** Called when the activity is first created. */
public static ArrayList<Integer> list1 = new ArrayList<Integer>();
Integer[] text;
int cnt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list1.add(R.raw.intro_letter_report_card);
list1.add(R.raw.intro_title_page2);
text = list1.toArray(new Integer[list1.size()]);
for(int i=0;i<text.length;i++)
{
cnt++;
File sd = Environment.getExternalStorageDirectory();
File folDirectory = new File("/sdcard/Songsnew1/");
// have the object build the directory structure, if needed.
folDirectory.mkdirs();
File source = new File(""+text[i]);
File destination= new File(folDirectory, "song"+cnt+".mp3");
if(source.exists()){
try {
FileChannel src = new FileInputStream(source).getChannel();
FileChannel dst = new FileOutputStream(destination).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}