80 likes | 91 Views
Learn about file systems, files, directories, and object serialization in C++/CLI. Explore sequential and random access files, file and directory manipulation, and common file dialog boxes.
E N D
File Systems • Files and directories • Absolute and relative names • Text and binary files • Sequential-access and random-access files
File and FileInfo in C++/CLI • File::Exists(path) • FileInfo^ file = gcnew FileInfo( path ); • file->Exists • file->FullName • file->Length • file->Directory • file->isReadOnly • http://msdn.microsoft.com/en-us/library/system.io.file.aspx • http://msdn.microsoft.com/en-us/library/system.io.fileinfo.aspx
Directory and Directory Info in C++/CLI • Directory::Exists(path) • DirectoryInfo^ dir=gcnew DirectoryInfo(path); • dir->Exists • dir->FullName • dir->Parent • array<FileInfo^>^ GetFiles() • array<DirectoryInfo^>^ GetDirectories() • http://msdn.microsoft.com/en-us/library/system.io.directory.aspx • http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx
Sequential-access Text File in C++/CLI • StreamReader ^sr = File::OpenText(name); • StreamReader ^sr = gcnew StreamReader(name); • sr->Read(); // read one char • sr->ReadLine(); // read one line • sr->Close() • StreamWriter ^sw = gcnew StreamWriter(name); • sw->Write(“string”); • sw->WriteLine(“string”); • sw->Close()
Object Serialization in C++/CLI • [Serializable] ref class MyObject {} • BinaryFormatter ^bf = gcnew BinaryFormatter() // SoapFormatter, XML-based • FileStream output = File::Create(name); • bf->Serialize(output, obj); // MyObject obj; • output.close(); • BinaryFormatter ^bf = gcnew BinaryFormatter() • FileStream input = File::OpenRead(name); • MyObject^ obj = (MyObject^)bf->Deserialize(input); • input.close();
Common File Dialog Boxes • OpenFileDialog • http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.aspx • SaveFileDialog • http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog.aspx
Announcements • Project #5 will be posted today, and will be due on April 5. • A solution for a project similar to Project #3 will be sent today.