I want to use the random files in basic4android. In basic4ppc it was:
FileOpen (c1, "text.dat",cRandom)
s = FileGet (c1, 5,10) 's will be a string with 10 characters starting from the sixth character in the file.
FileClose(c1)
You should use the RandomAccessFile library.
If you want to read strings you can read the bytes and then use BytesToString keyword to convert the bytes into string.
What exactly are you trying to do?
To open a file you can use code similar to:
B4X:
Dim raf As RandomAccessFile
raf.Initialize(File.DirRootExternal, "1.dat", False)
Dim i As Int
i = raf.ReadInt(12) 'reads an integer stored in the 12 position.
Dim buffer(1024) As Byte
raf.ReadBytes(buffer, 0, 100, 1000) 'reads 100 bytes starting at position 1000
Dim s As String
s = BytesToString(buffer, 0, 100, "UTF-8") 'convert the bytes to string
It's an error by Erel. ReadBytes returns an integer count of bytes read and so cannot be assigned to an array variable. It should be something like
B4X:
Dim bytesread as Int
bytesread = acceso.ReadBytes(buffer,0,100,1000)
If I remember correctly ReadBytes doesn't guarantee to always return the numbert of bytes requested - but probably will in the case of a file. It might be wise to check the return value for the correct number of bytes.