I'm learning C # right now and I've gotten to a point with console applications where I'm about to learn how to read data from a text file. Before I start learning how to make a program do this I've been trying to find out why you would want to do this. I always feel that if I understand why I'm doing something then I can better understand the benefits of it and give it the time it deserves when being taught. I would greatly appreciate it if someone could tell me when and how you would use something like reading data from a text file and what the benefits are? I have been looking for a couple of weeks now and can't find anything and I need to get started. Thank you in advance.
Best How To :
At the most basic level, you read data from a text file because the data you need is stored in a text file (as opposed to a database or retrieved from a web service call).
Why is data stored in text files? Many reasons:
- Text files are amongst the easiest files to create and process. Un*x comes with a whole plethora of tools for creating, searching, filtering and modifying them and many have been ported to Windows.
- Little can go wrong with text files. Indexes can get corrupted on databases. Database file formats vary from one database to the next and so on. A simple CSV (comma separated variable) file is a form of text file that is almost universally supported.
- Editing a text file is easy. No need for heavy graphical editors. You can use anything from Notepad to vim, Emacs or Sublime.
- Programmatically, text files do not require heavy libraries to access.
These days, data is stored in text files usually for:
- Configuration (since little can go wrong and it is easy to edit)
- Logging (since they are easy to create and view)
- Sharing data between systems (since they are a lowest common denominator). Remember that HTTP, SMTP and many common Internet standards are based on text.
- Historical or legacy systems that could be updated to use a database or something more appropriate.