Android Question Problem With Job.PostFile

ian2410

Member
Licensed User
Hi,

I'm Ian and newbie with B4A. I can send string to PC but I have a problem sending text file to PC (with B4J server).

I'm using a tablet with Android version 6.0.

java.io.FileNotFoundException: /data/user/0/b4a.example/files/temp.text: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:487)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:209)
at anywheresoftware.b4a.samples.httputils2.httpjob._postfile(httpjob.java:235)
at b4a.example.cekorder._button4_click(cekorder.java:708)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:473)

mycode :

Dim Job As HttpJob
Job.Initialize("Job", Me)
Job.JobName = "Sent"
Job.PostFile(link2, File.DirRootExternal, "temp.text")

i'm sure that "temp.text" is exist cause i can open the "temp.text" with File.ReadString.

Any advice ?

Thanks a lot.
 

ronell

Well-Known Member
Licensed User
add this code before the job

B4X:
If File.Exists(File.DirRootExternal,"temp.txt") = False Then
            File.WriteString(File.DirRootExternal,"temp.txt", _
                "")
           
            Else

            End If
 
Upvote 0

ronell

Well-Known Member
Licensed User
take a look at the error
java.io.FileNotFoundException: /data/user/0/b4a.example/files/temp.text: open failed: ENOENT (No such file or directory)
temp.txt is being search in your project folder(assets)?

edit:
i test it with this code , without the file in DirRootExternal..
B4X:
Dim job As HttpJob
         job.Initialize("job1",Me)
         job.PostFile("link",File.DirRootExternal,"sample.txt")

error:
java.io.FileNotFoundException: /storage/sdcard0/sample.txt: open failed: ENOENT (No such file or directory)
 
Last edited:
Upvote 0

ian2410

Member
Licensed User
My main purpose is to print "temp.text" which contains multi line text with printhtml. anyway, i've found another way to print that.
i did this :

EditText1.Text = File.ReadString(File.DirRootExternal, "temp.txt")

then

i just post it as string and now i can print multi line text successfully to 4 different printers simultaneously.
 
Upvote 0

ian2410

Member
Licensed User
i don't know, ronell. same errors occurred if i try to delete or copy "temp.text" .
"temp.text" is exist but somehow the file not found.
 
Upvote 0

ronell

Well-Known Member
Licensed User
in activity create .. you are copying the file in dirInternal, change it to DirRootExternal
in Sent button(button3_click) , change the file name to temp.txt , not temp.text

B4X:
Activity.LoadLayout("Main")
 
    If File.Exists(File.DirRootExternal, "temp.txt") = False Then
     
        File.Copy(File.DirAssets, "temp.txt", File.DirRootExternal, "temp.txt")
    End If


B4X:
Sub Button3_Click

    Dim job As HttpJob
    job.Initialize("job", Me)
    job.JobName = "Sent"
    job.PostFile(link, File.DirRootExternal,"temp.txt")
End Sub
 

Attachments

  • testapp.zip
    8.4 KB · Views: 184
Last edited:
Upvote 0

ian2410

Member
Licensed User
sorry for my mistake in the sample. but in my actual app, i type it right. i've tried yours...

java.io.FileNotFoundException: /storage/sdcard0/temp.txt: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:496)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:209)
at anywheresoftware.b4a.objects.streams.File.ReadString(File.java:271)
at b4a.example.main._button2_click(main.java:448)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4848)
at android.view.View$PerformClick.run(View.java:20262)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
 
Upvote 0

ian2410

Member
Licensed User
but it works in android 5.0, failed in android 6.0.

finally, it works when i set :

android:maxSdkVersion="22"

previously "23". don't know why.

Thanks a lot
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
If you use Api 23 you MUST USE RUNTIMEPERMISSIONS Library and request Permission for any "dangerous Permission" like write on external storage
 
Upvote 0
Top