Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

StreamWriter is not accurate

$
0
0

Hello.

1)I read binary file

2)convert every two byte to int value

3)convert value to string

4)write string value to a new line of txt file

namespace ECGReader
{
    class Program
    {
        static void Main(string[] args)
        {
            BinaryReader br = new BinaryReader(File.Open(@"e:\uchebaka\PolyGraph\00001101.ECG", FileMode.Open, FileAccess.Read));
            List<int> values = new List<int>();
            while (br.BaseStream.Position != br.BaseStream.Length)
            {
                values.Add(br.ReadInt16());
            }
            br.Close();

            StreamWriter sr = new StreamWriter(@"e:\uchebaka\PolyGraph\00001101.txt");
            for (int i = 0; i < values.Count; i++)
            {
                if (i == 3131734)
                {
                    int a = values[i];
                }
                sr.WriteLine(Convert.ToString(values[i]));
            }
        }
    }
}
The problem is, that count of List "values" - 3131735 and "values[3131734]" = 29, but when I check .txt file last string index is 1000-500 values far from original Length(last value in .txt file is not 29), why streamwriter avoids writing random amount of last values?


Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>