private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
try
{
FileStream ^fileInput = gcnew FileStream("myfile.txt", FileMode::OpenOrCreate, FileAccess::ReadWrite);
StreamReader ^streamIn = gcnew StreamReader(fileInput);
while(!streamIn->EndOfStream)
{
listBox1->Items->Add(streamIn->ReadLine());
};
streamIn->Close();
}
catch(IOException ^)
{
textBox1->Text="something went wrong";
}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
{
try
{
FileStream ^outFile = gcnew FileStream("mynewfile.txt", FileMode::Create, FileAccess::Write);
StreamWriter ^streamOut = gcnew StreamWriter(outFile);
streamOut->WriteLine(textBox1->Text);
streamOut->Close();
}
catch(IOException ^)
{
textBox1->Text="something went wrong";
}
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e)
{
String ^myfile = "";
openFileDialog1->ShowDialog() ;
myfile = openFileDialog1->FileName;
try
{
FileStream ^fileInput = gcnew FileStream(myfile, FileMode::OpenOrCreate, FileAccess::ReadWrite);
StreamReader ^streamIn = gcnew StreamReader(fileInput);
while(!streamIn->EndOfStream)
{
listBox1->Items->Add(streamIn->ReadLine());
};
streamIn->Close();
}
catch(IOException ^)
{
textBox1->Text="something went wrong";
}
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e)
{
String ^myfile = "";
saveFileDialog1->ShowDialog() ;
myfile = saveFileDialog1->FileName;
try
{
FileStream ^outFile = gcnew FileStream(myfile, FileMode::Create, FileAccess::Write);
StreamWriter ^streamOut = gcnew StreamWriter(outFile);
streamOut->WriteLine(textBox1->Text);
streamOut->Close();
}
catch(IOException ^)
{
textBox1->Text="something went wrong";
}
}
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e)
{
try
{
FileStream ^outFile = gcnew FileStream("myfile.txt", FileMode::Append, FileAccess::Write);
StreamWriter ^streamOut = gcnew StreamWriter(outFile);
streamOut->WriteLine(textBox1->Text);
streamOut->Close();
}
catch(IOException ^)
{
textBox1->Text="something went wrong";
}
}
|