Android Question WriteBytes <> adding new bytes to old bytes

Tayfur

Well-Known Member
Licensed User
Longtime User
Hello I have "TRESIM.DAT" files. And it has a 10byte data.
(data="TC}Ñ╩12#╣A" )

After, I want to add 5byte data. (bytes =ASDFGH)
(new file "TRESIM.DAT" = data+bytes = "TC}Ñ╩12#╣AASDFGH")
and save this file . But I cant it.

How can it


B4X:
Dim raf As RandomAccessFile
                    raf.Initialize(File.DirRootExternal, "TRESIM.dat", False)
 s=raf.Size
'*** bytes=ASDFGH                    
                    raf.WriteBytes(bytes,0,bytes.Length-1,raf.CurrentPosition)
                    raf.Close
 

stevel05

Expert
Licensed User
Longtime User
Try setting the current position

B4X:
raf.CurrentPosition = raf.size -1

before writing
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
It should be:
B4X:
raf.CurrentPosition = raf.Size

thank you Erel; its works.

I use AsyncStreams. And file transfer (2-4 mb) from PC to Phone.
My way is.
PC:
1-Convert byte data >> hex data
2-Send to phone (max length =1024)

Phone
1- Recive data
2- convert hex to byte
3- write+add in file
Only problem AsyncStreams cant recive byte data. I send to pfoen from byte data (for examplae 600byte). Phone recive (415byte) . bytheway I convert to byte to hex, and after send it.

How can recive byte data?
 
Upvote 0
Top