Sub Process_Globals
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
If File.ExternalWritable = False Then
Msgbox("Cannot write on storage card.", "")
Return
End If
SaveStringExample
ReadStringExample
WriteListExample
ReadListExample
WriteMapExample
ReadMapExample
WriteTextWriter
ReadTextReader
End Sub
Sub SaveStringExample
File.WriteString(File.DirRootExternal, "String.txt", _
"This is some string" & CRLF & "and this is another one.")
End Sub
Sub ReadStringExample
Msgbox(File.ReadString(File.DirRootExternal, "String.txt"), "")
End Sub
Sub WriteListExample
Dim List1 As List
List1.Initialize
For i = 1 To 100
List1.Add(i)
Next
File.WriteList(File.DirRootExternal, "List.txt", List1)
End Sub
Sub ReadListExample
Dim List1 As List
'We are not initializing the list because it just holds the list that returns from File.ReadList
List1 = File.ReadList(File.DirRootExternal, "List.txt")
Msgbox("List1.Size = " & List1.Size & CRLF & "The third item is: " & List1.Get(2), "")
End Sub
Sub WriteMapExample
Dim Map1 As Map
Map1.Initialize
For i = 1 To 10
Map1.Put("Key" & i, "Value" & i)
Next
File.WriteMap(File.DirRootExternal, "Map.txt", Map1)
End Sub
Sub ReadMapExample
Dim Map1 As Map
'Again we are not initializing the map.
Map1 = File.ReadMap(File.DirRootExternal, "Map.txt")
'Append all entries to a string builder
Dim sb As StringBuilder
sb.Initialize
sb.Append("The map entries are:").Append(CRLF)
For i = 0 To Map1.Size - 1
sb.Append("Key = ").Append(Map1.GetKeyAt(i)).Append(", Value = ")
sb.Append(Map1.GetValueAt(i)).Append(CRLF)
Next
Msgbox(sb.ToString,"")
End Sub
Sub WriteTextWriter
Dim TextWriter1 As TextWriter
TextWriter1.Initialize(File.OpenOutput(File.DirRootExternal, "Text.txt", False))
For i = 1 To 10
TextWriter1.WriteLine("Line" & i)
Next
TextWriter1.Close
End Sub
Sub ReadTextReader
Dim TextReader1 As TextReader
TextReader1.Initialize(File.OpenInput(File.DirRootExternal, "Text.txt"))
Dim line As String
line = TextReader1.ReadLine
Do While line <> Null
Log(line) 'write the line to LogCat
line = TextReader1.ReadLine
Loop
TextReader1.Close
End Sub