Hi,
A couple of questions about using the SDCard because I see some strange behaviors while testing. I use a Spider in Gadgeteer mode. I’m basically looking at managing a set of configuration files stored in a directory. I need to read and write key/value pairs as lines in files.
First : Does the gadgeteer code listed as SDCard usage examples on SDCard description work on Premiums as well ?
When I write lines into a simple file, it’s not always written down to the SDCard. The following code should add 10 lines to a file and close it but that does not work systematically. What do I do wrong ? (I fire this function in the SDCard mount event…)
public void WriteLine(string file, string line)
{
StreamWriter tw = new StreamWriter( file,true );
for (int i = 0; i < 10; i++)
{
tw.WriteLine( i.ToString () + " : " + line);
Debug.Print(i.ToString() + " : " + line);
}
tw.Flush();
tw.Close();
}
Reading files looks ok using the following code :
public void ReadFile(string fileName)
{
if ((fileName != null) && File.Exists(fileName))
{
using (StreamReader input = new StreamReader(fileName))
{
string textLine = input.ReadLine();
while (textLine != null)
{
Debug.Print(textLine);
textLine = input.ReadLine();
}
input.Close();
}
}
else
{
Debug.Print("SDCardService : file doesn't exist");
}
}
Thanks.
Stephan