Android Question Reading very large files to a byte buffer

prokli

Active Member
Licensed User
Longtime User
Hello everybody!

This code works fine for small files:

IfFile.Exists(dirName, fiName) Then
raf.Initialize(dirName, fiName, False)
fileS = File.Size(dirName, fiName)
Dim ooBuffer(fileS)AsByte
raf.ReadBytes(ooBuffer,0,fileS,raf.CurrentPosition)
AStreams.Write(ooBuffer)

End If
I want to transfer a file on my android device to a Windows PC via Socket.

"raf" is defined As RandomAccessFile
For very large files I always get a "Out of Memory" message.
Has anybody an example?
Thx
Harald
 

prokli

Active Member
Licensed User
Longtime User
Thanks, Erel!
This is a very good aproach. I will even move from VBA to B4J :eek:))
Thx
 
Upvote 0

prokli

Active Member
Licensed User
Longtime User
Hello!
I downloaded and installed " http://www.b4x.com/android/fo...ceive-objects-over-the-network.34612/#content" (B4J and B4A)
Whenever I send a file from PC to my android device, I receive a number but not a file Name (see *** in code below)!


Sub astreamO_NewObject(Key AsString, Value AsObject)

Select Key
Case"form"
Dim p AsPerson = Value
txtFirst.Text = p.First
txtLast.Text = p.Last
txtAnimal.Text = p.Animal

Case"simple value"
Dim number AsInt = Value
Log("Received lucky number: " & number)

Case"image"
Dim bmp AsImage = Value
cvs.DrawImage(bmp, 0, 0, cvs.Width, cvs.Height)

Case"file"
Dim fileName AsString = Value '*** value is always a number, never a file name
Log("Received file. File size: " & File.Size(astreamO.TempFolder, fileName))
EndSelect

End Sub

How can I get the real file Name as it has been transmitted by PC??
If the file is very large I get a Log "sending message to waiting queue" and astreamO_NewObject() is never called again!

Thx
 
Upvote 0
Top