Android Question File not exist

Almog

Active Member
Licensed User
Hello,

I tried to use OkHttpUtils2 to download a file from a link (trying to download file named "rec.zip")

B4X:
        Dim d As HttpJob
        d.Initialize("", Me)
        d.Download(link)
        Wait For (d) JobDone(d As HttpJob)
        If d.Success Then
            If Not(File.IsDirectory(File.DirRootExternal , "/rec")) Then
                File.MakeDir(File.DirRootExternal, "rec")
            End If
            Dim out As OutputStream = File.OpenOutput(File.DirRootExternal & "/rec" , "rec.zip", False)
          
            File.Copy2(d.GetInputStream, out)
       
            out.Close
        End if
and get an error :


Error occurred on line: 73 (Main)
java.io.FileNotFoundException: /storage/emulated/0/rec/rec.zip (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:448)
at com.b4a.example.main$ResumableSub_Activity_Create.resume(main.java:607)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:245)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:365)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)


Does anybody know how to solve this problem?

Thanks in advance.
 
Top