1 / 8

File Systems

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.

mistyn
Download Presentation

File Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. File Systems • Files and directories • Absolute and relative names • Text and binary files • Sequential-access and random-access files

  2. 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

  3. 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

  4. 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()

  5. 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();

  6. 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

  7. An Example

  8. 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.

More Related