How to read or write to a file using Visual Basic

Asked By 0 points N/A Posted on -
qa-featured

Hi all,

I have installed Visual Studio 2010 on Window 7.

I am learning Visual Basic now a days and having trouble in file reading and writing.

Can anyone tell me that how can I read or write to a .txt file using Visual Basic?

Thanks in Advance.

SHARE
Answered By 0 points N/A #117897

How to read or write to a file using Visual Basic

qa-featured

The  OpenTextFileReader procedure of the My.Computer.FileSystem will allow you to read a document or file, singe line one by one . You can also use the other method of reading a file by undergoing ReadLine procedure, one line of text at once .

Read from a text document or file by using the ReadAllText procedure of the My.Computer.FileSystem item.. You can read a single line of documents into a string by  providing the path after that it will then appear in a message or dialog box. See the example below 1st image.

Write a text to a document or  file by using WriteAllText Procedure, and simply noting the text and documents that you want to write.You will see that the  “This is new text” line  is written into the document test.txt, this will allow the  new text  to join the current and existing text in the file. 

See the example below 2nd  image.

Login/Register to Answer

Related Questions