2013-08-01 9 views
0

그래서 MediaRecorder로 무언가를 녹음하고 안드로이드 장치 어딘가에 넣으십시오. 그 파일의 이름을 어떻게 바꿉니 까? 이것은 내가 솔루션에있어 가장 가까운 것입니다. 버튼을 클릭하면 아무 일도 일어나지 않습니다.기존 파일의 이름을 바꾸려면 어떻게합니까?

public void nameAlert() { 
    AlertDialog.Builder nameAlert = new AlertDialog.Builder(this); 
    nameAlert.setMessage("Name of your recorded file:"); 
    final EditText input = new EditText(this); 
    nameAlert.setView(input); 

    nameAlert.setPositiveButton("Enter", new DialogInterface.OnClickListener() { 

     @Override 
     public void onClick(DialogInterface arg0, int arg1) { 
      newFileName = input.getText(); 
      String currentFileName = externalStoragePath; 
      currentFileName = currentFileName.substring(1); 
      Log.i(storagePath, currentFileName); 

      File directory = new File (externalStoragePath); 
      File from = new File (directory, currentFileName); 
      File to = new File (directory, newFileName + ".mp3"); 
      from.renameTo(to); 
     } 
    }); 
    nameAlert.show(); 

또한 관련있을 수 있습니다.

externalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath(); 

로그 :

08-02 02:04:03.623: I/(14043): storage/emulated/0 
+1

귀하의 코드가 꽤 많이하는 것만 큼 간단을 반환하므로 그것은 얻을 수있다. – FabianCook

+0

@SmartLemon 어떤 생각이 잘못 될 수 있습니까? – Pizzret

+0

Wheal onclick 코드? – FabianCook

답변

0

을 수행 할 수 있습니다! 나는이로 변경

File directory = new File (externalStoragePath); 

: 문제는이 줄을이었다

File directory = new File (externalStoragePath + File.separator + "/Android/data/com.whizzappseasyvoicenotepad/"); 

externalStoragePath이 (파일 이름 포함) 전체 경로

0

File 기준으로하는 방법. 많은 실패가 가능합니다. 더 많은 가능성이있는 오류 중 일부는 다음과 같습니다.

  1. 원본 및 대상 경로를 모두 포함하는 디렉터리에 대한 쓰기 권한이 필요합니다.
  2. 두 경로의 모든 부모에게는 검색 권한이 필요합니다.
  3. 두 경로가 모두 동일한 마운트 지점에 있어야합니다. Android에서는 응용 프로그램이 내부 저장소와 SD 카드간에 복사를 시도 할 때 이러한 제한을받을 가능성이 큽니다. 이 메서드는 실패하면 IOException을 throw하지 않습니다. 발신자는 반환 값을 확인해야합니다.

한 번에 하나씩 다시 확인할 수 있습니까? 무슨 일이 일어나고 있는지 알 수있을 것 같아.

+0

그냥 알아 냈어, 그 실패한 건 아니야, 내 대답을 확인해, 어쨌든 고마워! – Pizzret

0

확인 먼저 파일이 excisting 경우 : 나는 그것을 알아 낸 을 그리고 그것은 여전히 ​​작동하지 말아 경우가있다는 수동으로 실시

if(to.exists()) throw new java.IOException("file exists"); 
    if (from.renameTo(to)) { 
     //success 
    }else{ 
     to.createNewFile(); 
     FileChannel FCfrom = null; 
     FileChannel FCto = null; 
     try { 
      FCfrom = new FileInputStream(from).getChannel(); 
      FCto = new FileOutputStream(to).getChannel(); 
      long count = 0; 
      long size = source.size();    
      while((count += destination.transferFrom(source, count, size-count))<size); 
     }finally { 
      if(FCto != null){ 
       FCto.close(); 
       FCfrom.close(); 
       from.delete(); 
     } 
    } 
+0

미안하지만, 나는 방금 전에 그것을 알아 냈다 :) 감사 어쨌든 친구! – Pizzret

관련 문제