StreamReader is a class file which is designed for reading a line of information from a text file and it is inherited from the abstract base class TextReader and this base class represents a reader, which can read a sequential series of characters.
The StreamWriter class is used to write data or information to the text file. It is a class file which is inherited from the abstract class TextWriter which can write a sequential series of characters. So, as per the given requirement lets, we create a simple example for better understanding. Here we will see the different kinds of ways one by one to read a text file in c. So, first, you have to design a user interface with one textbox for getting text file path from the user as an input, a read-only multiline textbox for show data of the text file and one simple button and on the click event of button we will read text file and display result in read-only multiline textbox.
Here I have used bootstrap to create clean an creative user interface you can also use your own CSS as per your requirements.
Now, let's start to write c code for the read text file and for that you have to write the following code as shown below. Before starting to write a code you have to add the following namespace. Method 1: Read the text file into the string using File. As you can see in this example we have used static class File and used File.
ReadAllText method. Method 2: Read text file into the string using streamreader. Here, we have used streamreader and using this class we have read the text file but if you observe then we have also used " using " statement that ensures that the method StreamReader. Again this is a very easy way to use static class File as shown in method 1, here we have used File. Creating and storing data on to a file in server is an important method of storing UserLogs, ErrorLogs and information generated by our website.
By storing text contents on to a file we can track our user activities and any exceptions which can be occurred because of errors. In this post we will see How we can create Text file and write text contents to the newly created file in ASP. The simple approach is to use StreamWriter to write to file and File. Create to create the file. This method accepts two String parameters.
One for file name and other for the file contents. If the file exists, it will append the Text content in it. If File. Exists filePath Then. End Using. End If. Return fileText. End Function. Now over to you:. A blog is nothing without reader's feedback and comments. Stay tuned and stay connected for more technical updates. Tweet Share Share Share. Lalit Raghuvanshi Read More. Next « Prev Post. Previous Next Post ». Conversion Clean.
0コメント