Android Question java.io.FileNotFoundException: /storage/emulated/0/file.xlsx: open failed: EPERM (Operation not permitted)

crazy_pvg

New Member
- Hii...
- i made a excel file using php and after making it i added code
to download it. i get error at following line.
B4X:
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, FileName, False)

- and the error is like this
B4X:
java.io.FileNotFoundException: /storage/emulated/0/file.xlsx: open failed: EPERM (Operation not permitted)
    at libcore.io.IoBridge.open(IoBridge.java:492)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)

- I gave permission to access internal storage.
- so how can i solve the error.
- my full code is given below
B4X:
Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("http://mysitename/")
            
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.Tag)
        Log(j.GetString)
        Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, FileName, False)
        File.Copy2(j.GetInputStream, out)
        out.Close
        
                
    Else
        Dim rerror As String
        Log("Error: " & j.ErrorMessage)
        rerror="Error: " & j.ErrorMessage
        rerror=rerror.Length
        Log(rerror)
            
        MsgboxAsync("Please connect to internet","Message")
        Return
            
    End If
            
    j.Release
 

Mahares

Expert
Licensed User
Longtime User
I gave permission to access internal storage.
You don't give permission to access the File.Dirinternal. You need permission to File.DirRootExternal,. There are tons of threads dealing with this complex problem.
It is a permission problem.Start here and drill down to more links after that.
 
Upvote 1

crazy_pvg

New Member
- Thank you @Mahares for the reply
- error is solved, As you said it is problem of permission.
- by watching - this vedio i recognized that in android 11
there is different permission for accessing dirRootexternal.
- after adding following line in manifest editor error got resolved because it showed permission to
access dirRootexternal like this - (Allow management of all files )
B4X:
AddPermission("android.permission.MANAGE_EXTERNAL_STORAGE")



WhatsApp Image 2022-03-21 at 9.08.55 PM.jpeg
 
Upvote 0
Top