2013-05-06 2 views
0

SD 카드에 저장되어있는 .3gp 오디오 파일을 가지고 있습니다. SD 카드의 다른 폴더에 파일을 복사하고 싶습니다. 나는 그것에 대해 많이 봤지만 아무런 효과가 없었습니다. 사람이 코드를 잖아 애들 경우 지금 아래에 주어진까지 내가 시도 도와 idea.Please :SD 카드에 .3gp 파일을 작성하십시오.

private void save(File file_save) { 

    String file_path = Environment.getExternalStorageDirectory() 
      .getAbsolutePath() + "/RecordedAudio"; 
    File file_dir = new File(file_path); 
    if (file_dir.exists()) { 
     file_dir.delete(); 
    } 
    file_dir.mkdirs(); 
    File file_audio = new File(file_dir, "audio" 
      + System.currentTimeMillis() + ".3gp"); 
    try { 

     ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
     ObjectOutput out = new ObjectOutputStream(bos); 
     out.writeObject(file_save); 
     out.close(); 
     FileOutputStream fos = new FileOutputStream(file_audio); 

     byte[] buffer = bos.toByteArray(); 
     fos.write(buffer); 

     fos.flush(); 
     fos.close(); 

    } catch (FileNotFoundException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

} 

이 항상 ... 코드 사전에 100.Thanks의 사이즈로 새로운 파일을 생성

mFileFirst = new File(mFileName);//mFileName is the path of sd card where .3gp file is located 
    save(mFileFirst); 
+0

다음 버퍼로 루프를 실행하지 않았습니까? – Raptor

+0

apache 공유에서 FileUtils를 사용해 보셨습니까? 'http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#copyFile(java.io.File, java.io.File)' – cahen

+1

https ://android.googlesource.com/platform/frameworks/base/+/9a7debe5857ffc7c71cfc4082b1b6d72a5cf81cd/core/java/android/os/FileUtils.java –

답변

0

을보십시오 : 나는 방법은() 저장이 전화 0
private void save(File file_save) { 
    String file_path = Environment.getExternalStorageDirectory() 
      .getAbsolutePath() + "/RecordedAudio"; 
    File file_dir = new File(file_path); 
    if (file_dir.exists()) { 
     file_dir.delete(); 
    } 
    file_dir.mkdirs(); 
    File file_audio = new File(file_dir, "audio" 
      + System.currentTimeMillis() + ".3gp"); 
    try { 

     FileInputStream fis = new FileInputStream(file_save); 
     FileOutputStream fos = new FileOutputStream(file_audio); 

     byte[] buf = new byte[1024]; 
     int len; 
     int total = 0; 
     while ((len = fis.read(buf)) > 0) { 
      total += len; 
      fos.write(buf, 0, len); 
      // Flush the stream once every so often 
      if (total > (20 * 1024)) { 
       fos.flush(); 
      } 
     } 
     fos.flush(); 
     fis.close(); 
     fos.close(); 

    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

} 
관련 문제