Hello,
I've got a problem reading a file in chunks and sending it via socket.
This is my code:
It always throws this error: (ArrayIndexOutOfBoundsException) java.lang.ArrayIndexOutOfBoundsException: length=0; regionStart=0; regionLength=1024
The file exists, so thats not the problem.
I hope someone can help me.
Best regards
I've got a problem reading a file in chunks and sending it via socket.
This is my code:
B4X:
Sub ReadFile(Dir As String, FileName As String)
Try
Dir = Dir & "/"
Log("Getting file:" & Dir & FileName)
Dim size As Long = File.Size(Dir,FileName)
Dim f As RandomAccessFile
f.Initialize(Dir,FileName,True)
Log(f.Size)
Do While f.CurrentPosition < size
Dim part() As Byte
f.ReadBytes(part,0,1024,f.CurrentPosition)
astream2.Write(part)
Loop
f.Close
astream2.Write("EOFEOFEOFEOFEOFX".GetBytes("UTF-8"))
Catch
Dim err As String = "notfound " & LastException.Message
astream2.Write(err.GetBytes("UTF-8"))
End Try
End Sub
It always throws this error: (ArrayIndexOutOfBoundsException) java.lang.ArrayIndexOutOfBoundsException: length=0; regionStart=0; regionLength=1024
The file exists, so thats not the problem.
I hope someone can help me.
Best regards