当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.Close方法代码示例

本文整理汇总了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);

        }
开发者ID:Raghavendra1509,项目名称:aifh,代码行数:33,代码来源:LinearRegressionExample.cs

示例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();
        }
开发者ID:riseven,项目名称:Xmas,代码行数:29,代码来源:Mundo.cs

示例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();
            }
        }
开发者ID:Xeonios,项目名称:XenoTorrent,代码行数:29,代码来源:Main.cs

示例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;
        }
开发者ID:jrafidi,项目名称:kinect-fencing-coach,代码行数:28,代码来源:KinectFileUtils.cs

示例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;
 }
开发者ID:dalinhuang,项目名称:video-event-detect,代码行数:31,代码来源:FileOperation.cs

示例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;
        }
开发者ID:tgy,项目名称:CSharp,代码行数:27,代码来源:IO.cs

示例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;

            }
        }
开发者ID:Sabashan-Ragavan,项目名称:Math-Tutor-Game,代码行数:33,代码来源:ExistingUser.cs

示例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;
        }
开发者ID:SJMakin,项目名称:Randoop.NET,代码行数:33,代码来源:Instrument.cs

示例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;
        }
开发者ID:petegee,项目名称:AHPilotStats,代码行数:30,代码来源:ProxySettingsDTO.cs

示例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;
 }
开发者ID:Evangileon,项目名称:TPO-emulator,代码行数:26,代码来源:LyricsReader.cs

示例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;
 }
开发者ID:zsjforgithub,项目名称:usp-zsj-01-15,代码行数:34,代码来源:HttpUtil.cs

示例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();
              }
        }
开发者ID:Craydel,项目名称:DM_UBER_TOOL,代码行数:30,代码来源:Reader.cs

示例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();
                }
            }
        }
开发者ID:cborrow,项目名称:ProjectStart,代码行数:26,代码来源:MainForm.cs

示例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();
         }
     }
 }
开发者ID:davidbedok,项目名称:oeprogvep,代码行数:25,代码来源:Edge.cs

示例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;
        }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:34,代码来源:Serializer.cs


注:本文中的System.IO.StreamReader.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。