Creating a file to use with RandomAccessFile

mattdavis523

Member
Licensed User
Longtime User
I'm trying to use RandomAccessFile to save data for the next time I open my app. I am able to build a csv file just fine, but when I go to build the .dat file I get an error about the file not existing. I have tried using a file browser to create a blank file, but still get the same error about "open failed: ENOENT (No such file or directory)"

Could you take a looke at the Build_Stats_dat sub?

thanks

B4X:
Sub Build_csv(Count As Int)
   Dim Stats_List As List
   Stats_List.Initialize
   Dim sb As StringBuilder
   sb.initialize
   Dim Temp_text As String : Temp_text = ", "
   For i = 0 To Count - 1
      Dim temp_list As List
      temp_list.Initialize
      Dim p As Player
      p = Players.Get(i)
      sb.Append(p.Name).Append(Temp_text)
      'temp_list.Add(p.Values)
      For c = 0 To NUM_COLUMNS - 1
         Dim pc As PlayerColumn
         pc.Player = p
         pc.Column = c
         If c < NUM_COLUMNS - 1 Then
            sb.Append(p.Values(c)).Append(Temp_text)
         Else
            sb.Append(p.Values(c))
         End If
      Next
      sb.Append(CRLF)
   Next
   File.MakeDir(File.DirRootExternal,"Volleyball/stats/")
   File.WriteString(File.DirRootExternal,"Volleyball/stats/stats.csv", sb)
   Build_Stats_dat
End Sub
Sub Build_Stats_dat
   Dim raf As RandomAccessFile
   File.MakeDir(File.DirRootExternal,"Volleyball/dat/")
   raf.initialize("Volleyball/dat/", "temp.dat", False)
   raf.writeobject(Players, False, 1)
End Sub
Sub Load_Stats_click
   Dim raf As RandomAccessFile
   raf.initialize("Volleyball/dat/", "temp.dat", False)
   Players = raf.readobject(1)
   CreateListOfPlayers(Players.Size)
End Sub
 

stevel05

Expert
Licensed User
Longtime User
raf.initialize("Volleyball/dat/", "temp.dat", False) will need to be :

raf.initialize(File.Combine(File.DirRootExternal,"Volleyball/dat/"), "temp.dat", False)

or similar.

Same for load_stats...
 
Upvote 0
Top