本文整理汇总了C#中System.IO.FileInfo.ReadToEnd方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileInfo.ReadToEnd方法的具体用法?C# System.IO.FileInfo.ReadToEnd怎么用?C# System.IO.FileInfo.ReadToEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了System.IO.FileInfo.ReadToEnd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: buttonLoadData_Click
private void buttonLoadData_Click( object sender, EventArgs e )
{
if ( openFileDialogRefract.ShowDialog( this ) != DialogResult.OK )
return;
try
{
string Content = "";
using ( System.IO.StreamReader S = new System.IO.FileInfo( openFileDialogRefract.FileName ).OpenText() )
Content = S.ReadToEnd();
Content = Content.Replace( "\r", "" );
string[] Lines = Content.Split( '\n' );
List<PanelFresnelReflectance.RefractionData> Data = new List<PanelFresnelReflectance.RefractionData>();
READING_STATE State = READING_STATE.UNKNOWN;
bool InsertExisting = false;
for ( int LineIndex=0; LineIndex < Lines.Length; LineIndex++ )
{
string Line = Lines[LineIndex];
string[] Values = Line.Split( ' ', '\t' );
if ( Line == "" || Values.Length == 0 )
continue; // Skip empty lines
if ( Values.Length != 2 )
throw new Exception( "Unexpected line " + LineIndex + " does not contain exactly 2 values! (" + Line + ")" );
if ( Values[0].ToLower() == "wl" )
{
if ( Values[1].ToLower() == "n" )
State = READING_STATE.N;
else if ( Values[1].ToLower() == "k" )
State = READING_STATE.K;
else
throw new Exception( "Unexpected data type \"" + Values[1] + "\" at line " + LineIndex + ". Expecting either n or k." );
InsertExisting = Data.Count > 0; // Populate list or insert in existing one?
continue; // Skip this descriptor line
}
float wl;
if ( !float.TryParse( Values[0], out wl ) )
throw new Exception( "Failed to parse wavelength at line " + LineIndex );
float v;
if ( !float.TryParse( Values[1], out v ) )
throw new Exception( "Failed to parse " + (State == READING_STATE.N ? "n" : "k") + " at line " + LineIndex );
PanelFresnelReflectance.RefractionData D = null;
if ( InsertExisting )
{ // Find existing slot in list
foreach ( PanelFresnelReflectance.RefractionData ExistingD in Data )
if ( Math.Abs( ExistingD.Wavelength - wl ) < 1e-6f )
{ // Found it!
D = ExistingD;
break;
}
if ( D == null )
throw new Exception( "Failed to retrieve wavelength " + wl + " in existing array of values populated by " + (State == READING_STATE.N ? "k" : "n") + " values at line " + LineIndex );
}
else
{ // Simply append
D = new PanelFresnelReflectance.RefractionData() { Wavelength = wl };
Data.Add( D );
}
if ( State == READING_STATE.N )
D.n = v;
else
D.k = v;
}
outputPanelFresnelGraph.Data = Data.ToArray();
checkBoxData.Checked = true;
}
catch ( Exception _e )
{
MessageBox.Show( this, "Failed to load data file:" + _e.Message, "Argh!", MessageBoxButtons.OK, MessageBoxIcon.Error );
}
}