473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

c# - Reading from a text file

hi i want to read info from file.but its going into infinete loop.could help me in this
here is the code
Expand|Select|Wrap|Line Numbers
  1. #region filecreation and writing data to file
  2.  
  3.             FileInfo fi = new FileInfo(@"c:\\csharppgms\\stdinfo.txt");
  4.             StreamWriter sw1 = fi.AppendText();
  5.  
  6.             std:
  7.             Console.WriteLine("enter student name:");
  8.             string sname = Console.ReadLine();
  9.             Console.WriteLine("enter telugu marks:");
  10.             int telugu =int.Parse(Console.ReadLine());
  11.             Console.WriteLine("enter english marks:");
  12.             int english = int.Parse(Console.ReadLine());
  13.             Console.WriteLine("enter maths marks:");      
  14.             int maths = int.Parse(Console.ReadLine());
  15.  
  16.             //writing data to the file
  17.             sw1.WriteLine(sname + "|" + telugu + "|" + english + "|" + maths);
  18.  
  19.             Console.WriteLine("do you want to enter more details:y/n");
  20.             string s = Console.ReadLine();
  21.  
  22.             if (s.ToLower() == "y")
  23.             {
  24.  
  25.                 goto std;
  26.  
  27.  
  28.             }
  29.             sw1.Close();
  30.             #endregion
  31.  
  32.             #region reading data from file
  33.             StreamReader sr1 = fi.OpenText();
  34.             while (sr1.ReadLine() != null)
  35.             {
  36.                 Console.WriteLine(sr1.ReadLine());
  37.             }
  38.  
  39.             #endregion
  40.             Console.Read();
Aug 15 '12 #1
1 2131
Aimee Bailey
197 Expert 100+
Hey there, why don't you try something like this to see if it works instead:

Expand|Select|Wrap|Line Numbers
  1. foreach (string line in File.ReadAllLines(fi.FullName))
  2. {
  3.     Console.WriteLine(line);
  4. }
  5.  
Aimee
Aug 17 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
14
by: Job Lot | last post by:
I have tab delimited text file which gets populated on daily basis via automated process. New entry is written at the bottom. I need to create a utility which makes a copy of this file with 10 most...
8
by: Phil Slater | last post by:
I'm trying to process a collection of text files, reading word by word. The program run hangs whenever it encounters a word with an accented letter (like rôle or passé) - ie something that's not a...
7
by: Drew Berkemeyer | last post by:
Hello, I'm using the following code to read a text file in VB.NET. Dim sr As StreamReader = File.OpenText(strFilePath) Dim input As String = sr.ReadLine() While Not input Is Nothing...
4
by: Nina | last post by:
Hi everyone, Do you know why the following code only read certain number of lines of text file, but not the entire file? Dim sr As StreamReader Dim str As String Dim al As ArrayList = New...
4
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
1
by: John | last post by:
I have a process that reads a text file then uploads the data into a database table. The text file has 10 lines at the end of the file that are blank BUT it appears that the enter key or space bar...
3
by: John | last post by:
How can I tell if a line begins with a number instead of a character? I need to read a text file and some of the data begins with a character which is causing me an issue in reading and uploading...
2
by: jatindersingh80 | last post by:
Hi , i am reading a text file with token # but somtimes blank lines comes between the line at blank line the code gives exception of no such element the text files contains data after blank lines...
3
by: jasvinder singh | last post by:
Respected Sir/madam, Can you help in providing code in 'C' for Reading text file with n number of rows and columns and putting the result in arrays.The sample file is as follows: rim_label =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.