Received the Netduino Plus (f/w 4.1.0.6) last week and am getting to know it.
I'm having trouble detecting the end of a file when using StreamReader. The code below will output the contents of the file line by line, but it doesn't seem to detect the file end. The final Debug.Print statement after the do-while loop is not executed.
using System; using System.IO; using System.Net; using System.Net.Sockets; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; namespace SDRead { public class Program { public static void Main() { // write your code here string fileLine = ""; Directory.SetCurrentDirectory("\\SD"); StreamReader fileReader = new StreamReader("test.txt"); do { fileLine = fileReader.ReadLine(); Debug.Print(fileLine); } while (fileReader.Peek() != -1); fileReader.Close(); Debug.Print("End file read"); } } }
Any suggestions will be appreciated.
Cheers