1 / 8

File Systems

File Systems. Files and directories Absolute and relative names Text and binary files Sequential-access and random-access files. File System Input and Output. One time access vs over-a-period-of- time access One time: call a static member function

thao
Télécharger la présentation

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 System Input and Output One time access vs over-a-period-of- time access One time: call a static member function Over-a-period-of- time: create an instance of a class Classes for Directories Directory DirectoryInfo Classes for Files File FileInfo

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

  4. Directory and DirectoryInfo 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

  5. Opening Files and I/O • Open, Create, OpenRead, etc. • Open Methods • Mode: Append, Create, CreateNew, Open, etc • Access: Read, Write, ReadWrite • Share: None, Read, Write, ReadWrite • Stream, FileStream, StreamWriter, StreamReader

  6. Sequential-access Text File in C++/CLI • StreamReader ^sr = File::OpenText(name); // or: • 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()

  7. Object Serialization in C++/CLI • Dealing with complex classes • [Serializable] ref class MyObject {} • BinaryFormatter ^bf = gcnew BinaryFormatter() // SoapFormatter, XML-based • FileStream output = File::Create(name); • bf->Serialize(output, obj); // Store MyObject obj; • output.close(); • BinaryFormatter ^bf = gcnew BinaryFormatter() • FileStream input = File::OpenRead(name); • MyObject^ obj = (MyObject^)bf->Deserialize(input); //Restore MyObject obj • input.close();

  8. An Example

More Related