using namespace System::IO;

Read Bytes From A File


	__int64 FileByteNumber;
	int ReadByte;

	FileStream ^SourceFile = gcnew FileStream(SelectFileDialog->FileName, FileMode::Open, FileAccess::Read, FileShare::None);

	for (FileByteNumber = 0; FileByteNumber < SourceFile->Length; FileByteNumber++)
	{
		//----- READ EACH BYTE -----
		if ((ReadByte = SourceFile->ReadByte()) == -1)
			throw gcnew Exception("File read too short");

		//ReadByte has the value but is actually an integer
	}
	SourceFile->Close();

Overwrite Bytes In A File As Its Read


	//Use
	FileAccess::ReadWrite
	//and
	SourceFile->WriteByte(Convert::ToByte('-'))

To move back 1 byte before writing:
	SourceFile->Seek(-1,SeekOrigin::Current);
	SourceFile->WriteByte(Convert::ToByte('-'));
	SourceFile->ReadByte();

Read String From A File


	if (File::Exists(TemporaryDirectory + EXTERNAL_EXPORTER_STATUS_FILE))
	{
		StreamReader ^StreamReader1 = gcnew StreamReader(TemporaryDirectory + EXTERNAL_EXPORTER_STATUS_FILE);
		MyString = StreamReader1->ReadToEnd();
		StreamReader1->Close();
	}

 

 

 

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *