public void Run()
        {
            SDCardManager.Mount();

            Debug.Instance.Log("opening for write...");

            var fsWrite = new SDFileStream("SDTEST.TXT", System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);

            byte[] textBytes = Encoding.ASCII.GetBytes("Test of writing to an SD card");

            fsWrite.Write(textBytes, 0, textBytes.Length);

            fsWrite.Flush();

            fsWrite.Close();

            Debug.Instance.Log("opening for read...");

            var fsRead = new SDFileStream("SDTEST.TXT", System.IO.FileMode.Open, System.IO.FileAccess.Read);

            byte[] data = new byte[1];

            string test = "";

            // read to end of file
            while (fsRead.Read(data, 0, 1) > 0)
            {
                test += (char)data[0];
            }

            Debug.Instance.Log(test);

            fsRead.Close();
        }
Пример #2
0
        public static byte[] ReadAllBytes(string path)
        {
            using (var fsRead = new SDFileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                int bytesRead;

                byte[] result = new byte[fsRead.Length];

                int i = 0;

                // read to end of file
                while ((bytesRead = fsRead.Read(result, i, 4096)) > 0)
                {
                    i += bytesRead;
                }

                return result;
            }

            throw new Exception("Unable to load file");
        }