2017-09-19 14 views
0

다음은 start.mp4 파일의 내 SD 카드 경로입니다. 이 파일을 읽기 모드에서는 가져올 수 있지만 rw 모드에서는 열 수 없습니다. 런타임 권한도 부여했습니다.파일이 SD 카드에있는 경우에만 Fileoutputstream에서 파일을 열 수 없음

/storage/3263-6232/piyush/Download/start.mp4 : 열기 실패 : EACCES (권한이 거부)

이 코드입니다 :

//This is the sd-card path of the file which needs to be edited 

String sdCardPath = "/storage/3263-6232/piyush/Download/start.mp4"; 
File file = new File(sdCardPath); 
try{ 

RandomAccessFile rfs = new RandomAccessFile(file, "rw"); 

rfs.seek(file.length()); 
rfs.close(); 

} catch (IOException e) { 
    e.printStackTrace(); 
} 
In the above code I have taken sdcardpath to a file which exists in sdcard. Than after that whenever I tried to open that file in outputstream using RandomAccessFile it gives FilenotFound Exception: 

/storage/3263-6232/piyush/Download/start.mp4: open failed: EACCES (Permission denied) 
IT는 예외가 발생합니다
+2

"나는 RW 모드로 열 수 읽기 모드에서이 파일을 얻을 수 있지만, 아니다"- 당신은 [이동식에 임의의 파일에 대한 읽기/쓰기 액세스하지 않기 때문에 storage] (https://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html)을 Android 4.4 이상에서 사용할 수 있습니다. 이는 놀라운 일이 아닙니다. 그러나 스택 오버플로는 프로그래밍 질문 용이며 질문하지 않았습니다. – CommonsWare

답변

0

당신은 런타임 권한 요청 같은 해야한다 안드로이드 (6)과 이상을 사용하는 경우 :

private void requestPermission() { 

    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1); 

    } 

과에서 onCreate :

public void onCreate(){ 
requestPermission(); 
}