有问题的部分代码如下:
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Title = "打开文件";
fileDialog.Filter = "Nav文件(*.**n)|*.**n";
if (fileDialog.ShowDialog() == DialogResult.OK)
{
list = new List<NavFormat>();
//打开文件
FileStream fs = new FileStream(fileDialog.FileName, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
//循环读取数据
while (true)
{
if (sr.ReadLine().Substring(60) == "END OF HEADER")
{
break;
}
}
string data;
while (true)
{
data = sr.ReadLine();
if (data == null)
break;
NavFormat objFormat = new NavFormat();
objFormat.thisToc = new Toc();
//第一行信息
objFormat.satPrn = data.Substring(0, 2);
objFormat.thisToc.year = Convert.ToInt32(data.Substring(3, 2)) + 2000;
objFormat.thisToc.month = Convert.ToInt32(data.Substring(6, 2));
objFormat.thisToc.day = Convert.ToInt32(data.Substring(9, 2));
objFormat.thisToc.h = Convert.ToInt32(data.Substring(13, 1));
objFormat.thisToc.m = Convert.ToInt32(data.Substring(16, 1));
objFormat.thisToc.s = ConvertToDouble(data.Substring(18, 4));
objFormat.a0 = ConvertToDouble(data.Substring(23, 18));
objFormat.a1 = ConvertToDouble(data.Substring(42, 18));
objFormat.a2 = ConvertToDouble(data.Substring(61, 18));
//第二行信息
data = sr.ReadLine();
objFormat.IODE = ConvertToDouble(data.Substring(4, 18));
objFormat.Crs = ConvertToDouble(data.Substring(23, 18));
objFormat.DeltaN = ConvertToDouble(data.Substring(42, 18));
objFormat.M0 = ConvertToDouble(data.Substring(61, 18));
//第三行信息
data = sr.ReadLine();
objFormat.Cuc = ConvertToDouble(data.Substring(4, 18));
objFormat.e = ConvertToDouble(data.Substring(23, 18));
objFormat.Cus = ConvertToDouble(data.Substring(42, 18));
objFormat.sqrtA = ConvertToDouble(data.Substring(61, 18));
//第四行信息
data = sr.ReadLine();
objFormat.toe = ConvertToDouble(data.Substring(4, 18));
objFormat.Cic = ConvertToDouble(data.Substring(23, 18));
objFormat.oumiga0 = ConvertToDouble(data.Substring(42, 18));
objFormat.Cis = ConvertToDouble(data.Substring(61, 18));
//第五行信息
data = sr.ReadLine();
objFormat.i0 = ConvertToDouble(data.Substring(4, 18));
objFormat.Crc = ConvertToDouble(data.Substring(23, 18));
objFormat.w = ConvertToDouble(data.Substring(42, 18));
objFormat.OumigaDot = ConvertToDouble(data.Substring(61, 18));
//第六行信息
data = sr.ReadLine();
objFormat.IDot = ConvertToDouble(data.Substring(4, 18));
objFormat.Code = ConvertToDouble(data.Substring(23, 18));
objFormat.GPSweek = ConvertToDouble(data.Substring(42, 18));
objFormat.L2_flag = ConvertToDouble(data.Substring(61, 18));
//都两个空行,不存储数据
sr.ReadLine();
sr.ReadLine();
//添加数据到list集合中
list.Add(objFormat);
}
}
估计是 文件中根本就没有 END OF HEADER 字样
我加了断点,就一直运行,没反应了
其实你这么写太累赘了