File Systems Files and directories Absolute and relative
File Systems • • Files and directories Absolute and relative names Text and binary files Sequential-access and random-access files
File and File. Info in C++/CLI • • File: : Exists(path) File. Info^ file = gcnew File. Info( path ); file->Exists file->Full. Name file->Length file->Directory file->is. Read. Only http: //msdn. microsoft. com/enus/library/system. io. file. aspx • http: //msdn. microsoft. com/enus/library/system. io. fileinfo. aspx
Directory and Directory Info in C++/CLI • • Directory: : Exists(path) Directory. Info^ dir=gcnew Directory. Info(path); dir->Exists dir->Full. Name dir->Parent array<File. Info^>^ Get. Files() array<Directory. Info^>^ Get. Directories() http: //msdn. microsoft. com/enus/library/system. io. directory. aspx • http: //msdn. microsoft. com/enus/library/system. io. directoryinfo. aspx
Sequential-access Text File in C++/CLI • • • Stream. Reader ^sr = File: : Open. Text(name); Stream. Reader ^sr = gcnew Stream. Reader(name); sr->Read(); // read one char sr->Read. Line(); // read one line sr->Close() • • Stream. Writer ^sw = gcnew Stream. Writer(name); sw->Write(“string”); sw->Write. Line(“string”); sw->Close()
Object Serialization in C++/CLI • [Serializable] ref class My. Object {} • Binary. Formatter ^bf = gcnew Binary. Formatter() // Soap. Formatter, XML-based • File. Stream output = File: : Create(name); • bf->Serialize(output, obj); // My. Object obj; • output. close(); • Binary. Formatter ^bf = gcnew Binary. Formatter() • File. Stream input = File: : Open. Read(name); • My. Object^ obj = (My. Object^)bf->Deserialize(input); • input. close();
Common File Dialog Boxes • Open. File. Dialog • http: //msdn. microsoft. com/enus/library/system. windows. forms. openfiledi alog. aspx • Save. File. Dialog • http: //msdn. microsoft. com/enus/library/system. windows. forms. savefiledi alog. aspx
An Example
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.
- Slides: 8