2017-09-19 3 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) 
それは例外をスローします
+2

「私は読み取りモードでこのファイルを取得することができるが、RWモードで開くことができませんよ」 - あなたは[リムーバブル上の任意のファイルへの読み取り/書き込みアクセス権を持っていないので、ストレージ](https://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html)をご覧ください。これは驚くべきことではありません。しかし、スタックオーバーフローはプログラミングに関する質問のためのものであり、あなたは質問していません。 – CommonsWare

答えて

0

あなたはアンドロイド6、あなたがそのような実行時許可要求 をしなければならないの上を使用している場合:

private void requestPermission() { 

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

    } 

とあなたのonCreate:

public void onCreate(){ 
requestPermission(); 
} 
関連する問題