本文整理汇总了C#中System.IO.StreamReader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.Close方法的具体用法?C# StreamReader.Close怎么用?C# StreamReader.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了StreamReader.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public void Process()
{
// read the iris data from the resources
Assembly assembly = Assembly.GetExecutingAssembly();
var res = assembly.GetManifestResourceStream("AIFH_Vol1.Resources.abalone.csv");
// did we fail to read the resouce
if (res == null)
{
Console.WriteLine("Can't read iris data from embedded resources.");
return;
}
// load the data
var istream = new StreamReader(res);
DataSet ds = DataSet.Load(istream);
istream.Close();
// The following ranges are setup for the Abalone data set. If you wish to normalize other files you will
// need to modify the below function calls other files.
ds.EncodeOneOfN(0, 0, 1);
istream.Close();
var trainingData = ds.ExtractSupervised(0, 10, 10, 1);
var reg = new MultipleLinearRegression(10);
var train = new TrainLeastSquares(reg, trainingData);
train.Iteration();
Query(reg, trainingData);
Console.WriteLine("Error: " + train.Error);
}
示例2: Mundo
public Mundo(FileInfo file)
{
FileStream fs = file.OpenRead();
StreamReader sr = new StreamReader(fs);
StringReader str = new StringReader(sr.ReadToEnd());
CreateFromString(str);
sr.Close();
string firstLine = sr.ReadLine();
string[] size = firstLine.Split(' ');
tamX = int.Parse(size[0]) ;
tamY = int.Parse(size[1]) ;
celdas = new TypeCelda[tamX][];
for ( int i = 0 ; i < celdas.Length ; i++ )
{
celdas[i] = new TypeCelda[tamY];
}
for (int x = 0; x < tamX; x++)
{
for (int y = 0; y < tamY; y++)
{
celdas[x][y] = TypeCelda.Pasillo;
}
}
sr.Close();
}
示例3: InitSettings
public static void InitSettings()
{
if (File.Exists (ep+"/ini.txt"))
{
string s;
string[] st;
StreamReader sr = new StreamReader (ep + "/ini.txt");
try
{
s = sr.ReadLine ();
st = s.Split (("=") [0]);
tp = st [1];
s = sr.ReadLine ();
st = s.Split (("=") [0]);
dp = st [1];
sr.Close ();
}
catch
{
sr.Close();
NewIni();
}
}
else
{
NewIni();
}
}
示例4: ReadErrorsFromRecordingFile
public static List<double> ReadErrorsFromRecordingFile(string filename, int errorSet)
{
List<double> errors = new List<Double>();
StreamReader reader = new StreamReader(filename);
string line;
int count = 0;
while ((line = reader.ReadLine()) != null)
{
if (line.Contains("ERRORS"))
{
count++;
}
if (count == errorSet)
{
line = line.Split(':')[1];
string[] error = line.Split(',');
foreach (string s in error)
{
errors.Add(double.Parse(s.Trim()));
}
reader.Close();
return errors;
}
}
reader.Close();
return errors;
}
示例5: readFromFile
public static float[] readFromFile(string filePath)
{
StreamReader fileReader = null;
try
{
fileReader = new StreamReader(filePath);
}
catch(Exception e)
{
return null;
}
string line = fileReader.ReadLine();
if (line == null)
{
fileReader.Close();
return null;
}
int mark = 0;
string[] data = line.Split(',');
if (data[data.Length - 1].Equals(""))
{
mark = 1;
}
float []dataF = new float[data.Length-mark];
for (int i = 0; i < data.Length-mark; i++)
{
dataF[i] = (float)Convert.ToDouble(data[i]);
}
fileReader.Close();
return dataF;
}
示例6: FileToTab
public static int FileToTab(string filename, ref int[,] tab)
{
int j = 0;
StreamReader SR;
string line = "";
Sudoku.InitTab (tab);
try {
SR = new StreamReader (filename);
} catch (Exception) {
Console.WriteLine ("ERROR : File does not exist !");
return 1;
}
while ((line = SR.ReadLine()) != null && j < tab.GetLength(1)) {
if (line.Length < tab.GetLength (0)) {
Console.WriteLine ("ERROR : Bad file format, not enough character for the Sudoku.");
Console.WriteLine ("Need at least {0} !", tab.GetLength (0));
SR.Close ();
return 2;
}
for (int i = 0; i < tab.GetLength(0); ++i)
tab [i, j] = Convert.ToInt32 (line [i].ToString ());
++j;
}
SR.Close ();
return 0;
}
示例7: UsersCurrentLevel
private static int UsersCurrentLevel(string username)
{
try
{
StreamReader reader = new StreamReader("UserInformation.txt");
string line = "";
while (line != null)
{
line = reader.ReadLine();
if (line != null)
{
string[] userInformation = line.Split('/');
if (userInformation[0] == username)
{
reader.Close();
return int.Parse(userInformation[2]);
}
}
}
reader.Close();
return -1;
}
catch (Exception ex)
{
MessageBox.Show("Error reading from text file: " + ex.Message,
"Important", MessageBoxButtons.OK, MessageBoxIcon.Information);
return -1;
}
}
示例8: ParseMapFile
public static void ParseMapFile(string file, ref Dictionary<string, string> map)
{
//openfile
string line;
int count = 0;
System.IO.StreamReader filereader = new System.IO.StreamReader(file);
//read line by line
while ((line = filereader.ReadLine()) != null)
{
count++;
Console.WriteLine(line); //debug
line = line.Trim();
if (line.StartsWith("#") || line.Equals(""))
continue;
string[] methods = line.Split(';');
if (methods.Length != 2)
{
filereader.Close();
throw new InvalidFileFormatException("more/less than one splitter is detected on line "+count.ToString());
}
string keystr = methods[0].Trim();
string valstr = methods[1].Trim();
map[keystr] = valstr;
}
filereader.Close();
//string keystr = "System.Windows.Forms.MessageBox::Show";
//string valstr = "System.Console::Writeline";
//map[keystr] = valstr;
}
示例9: GetProxySettings
public static ProxySettingsDTO GetProxySettings()
{
ProxySettingsDTO proxySettings = new ProxySettingsDTO();
StreamReader reader = null;
try
{
reader = new StreamReader(".\\netconxsettings.xml");
XmlSerializer xSerializer = new XmlSerializer(typeof(ProxySettingsDTO));
proxySettings = (ProxySettingsDTO)xSerializer.Deserialize(reader);
reader.Close();
}
catch
{
if(reader != null)
reader.Close();
TextWriter writer = new StreamWriter(".\\netconxsettings.xml");
try
{
XmlSerializer serializer = new XmlSerializer(typeof(ProxySettingsDTO));
serializer.Serialize(writer, proxySettings);
}
finally
{
writer.Close();
}
}
return proxySettings;
}
示例10: ReadLRCFile
public string ReadLRCFile(string filePath)
{
Stream stream = null;
StreamReader reader = null;
string str = "";
string strInput = "";
try
{
stream = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
reader = new StreamReader(stream, Encoding.GetEncoding("gb2312"));
this.LrcList.Clear();
while (!reader.EndOfStream)
{
strInput = reader.ReadLine() + "\r\n";
str = str + this.regLrc(strInput);
}
reader.Close();
stream.Close();
}
catch
{
reader.Close();
stream.Close();
}
return str;
}
示例11: HttpRequestByGet
public static string HttpRequestByGet(string Url, CookieContainer cookieContainer)
{
HttpWebRequest webRequest = null;
WebResponse webResponse = null;
StreamReader sr = null;
string response = "";
try
{
webRequest = (HttpWebRequest)WebRequest.Create(Url);
if (cookieContainer != null)
{
webRequest.CookieContainer = cookieContainer;
}
webResponse = webRequest.GetResponse();
sr = new StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
response = sr.ReadToEnd();
sr.Close();
sr = null;
}
catch { }
finally
{
if (webResponse != null)
{
webResponse.Close(); ;
}
if (sr != null)
{
sr.Close();
sr = null;
}
}
return response;
}
示例12: GetResourcesPath
public void GetResourcesPath()
{
// read resourcesPath
if(!File.Exists(Application.StartupPath + "\\" + prefsFileName))
{
File.Create(prefsFileName).Close(); // create the file, and immediately release it
}
StreamReader reader = new StreamReader(Application.StartupPath + "\\" + prefsFileName);
if((resourcesPath = reader.ReadLine()) == null || !(new DirectoryInfo(resourcesPath).Exists))
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.SelectedPath = Application.StartupPath;
dlg.Description = "Please locate the 'Resources' directory (about 3 levels up from the debug directory) :";
if(dlg.ShowDialog() == DialogResult.Cancel)
Application.Exit();
resourcesPath = dlg.SelectedPath;
reader.Close();
StreamWriter output = new StreamWriter(Application.StartupPath + "\\" + prefsFileName);
output.WriteLine(resourcesPath);
output.Close();
}
else
{
reader.Close();
}
}
示例13: LoadContentTemplates
protected void LoadContentTemplates()
{
DirectoryInfo di = new DirectoryInfo(ContentTemplateManager.TemplatesPath);
foreach (FileInfo fi in di.GetFiles("*.ctpl"))
{
ContentTemplate template = new ContentTemplate();
using (StreamReader sr = new StreamReader(fi.OpenRead()))
{
if (sr.ReadLine() != "ContentTemplate")
{
sr.Close();
return;
}
template.Name = sr.ReadLine();
template.Shortcut = sr.ReadLine();
template.Mode = (ContentTemplateMode)Enum.Parse(typeof(ContentTemplateMode), sr.ReadLine());
template.Content = sr.ReadToEnd();
ContentTemplateManager.Manager.Add(template);
sr.Close();
}
}
}
示例14: load
public static void load(string fileName, Graph graph)
{
StreamReader reader = null;
try
{
reader = new StreamReader(File.Open(fileName, FileMode.Open));
String line = "";
while ((line = reader.ReadLine()) != null)
{
graph.add(Edge.parse(graph, line));
}
reader.Close();
}
catch (Exception e)
{
throw new BadFileFormatException("Unexpected error while parsing '" + fileName + "'.", e);
}
finally
{
if (reader != null)
{
reader.Close();
}
}
}
示例15: SerializeToText
public static string SerializeToText(System.Type ObjectType, Object Object)
{
string RetVal;
StreamWriter Writer;
StreamReader Reader;
MemoryStream Stream;
RetVal = string.Empty;
Stream = new MemoryStream();
Reader = new StreamReader(Stream);
Writer = new StreamWriter(Stream);
try
{
if (Object != null && ObjectType != null)
{
Serialize(Writer, ObjectType, Object);
Stream.Position = 0;
RetVal = Reader.ReadToEnd();
Writer.Flush();
Writer.Close();
Reader.Close();
}
}
catch (Exception ex)
{
Writer.Flush();
Writer.Close();
Reader.Close();
throw ex;
}
return RetVal;
}