Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

You can read a file using the IO::StreamReader object. Here is an example:

//create a new StreamReader object and pass in the path to the file
System::IO::StreamReader* r = new System::IO::StreamReader("path to the file");
//create a string variable to hold the value that you read from the file
//in this example you are only reading one line because ReadLine() method is used
String* fcontent = r->ReadLine();
//close the stream
r->Close();

This how you can read it, how you get out the info from the file is what you have to think of, it depends on how you format your file, where you put what and things like that.

If you want to write to a file use IO.StreamWriter class. Here is an example:

'create a new StreamWriter object and pass in the path to the file to it
System::IO::StreamWriter* w = new System::IO::StreamWriter("path to the file");
//now you can write to the file using WriteLine or Write method
w->WriteLine("This is a text");
//then you have to flush the sream to make sure everything is in the file now
w->Flush();
//and close it
w->Close();

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...