Содержание
- 2. Managing the files For many applications a common requirement is the ability to interact with the
- 3. .Net Classes that represent Files and Folders Directory and File contain only static methods. You use
- 4. FileInfo and DirectoryInfo properties You can use following properties
- 5. FileInfo and DirectoryInfo methods You can also perform actions on the file system object using the
- 6. Example: A File Browser that presents a simple user interface that allows you to browse around
- 7. Example: A File Browser Step 1. Create textBoxInput textBoxFolder buttonDisplay buttonUp listBoxFiles listBoxFolders textBoxFileName textBoxCreationTime textBoxFileSize
- 8. Example: A File Browser Step 3. Add a Step 4. Add ev Stores the path of
- 9. Example: A File Browser Step 5. Add t //clear the contents of al l controls protected
- 10. Example: A File Browser Step 5. Add t //Display information for a given file in the
- 11. Example: A File Browser Step 5. Add t //Display the contents of a given folder in
- 12. Example: A File Browser Step 5. Add t //Display button handlerpr otected void OnDisplayBu ttonClick(object sender
- 13. Example: A File Browser Step 5. Add t //Event handler that is ca lled when an
- 14. Example: A File Browser Step 5. Add t //Event handler for the se lection of a
- 15. Example: A File Browser Step 5. Add t //Event handler for Up but tonprotected void OnUpBu
- 16. Reading and Writing to Files Reading and writing to files is in principle very simple; however,
- 17. Actual hierarchy of stream-related classes in the System.IO namespace.
- 18. Streams FileStream — This class is intended for reading and writing binary data in a binary
- 19. Reading and Writing Text Files StreamReader Sr = new St reaReader(@”c:\Documents\ReadMe.txt”);//spe cif y encoding (ASCII, Unicode,
- 20. Reading and Writing Text Files void SaveFile(){ Stream Writer sw = new StreamWriter(chosenFile, fa lse ,
- 21. Чтение и запись двоичных данных string filePath = "..."; FileStream file = new FileStream(filePath); ... BinaryReader
- 22. Чтение и запись двоичных данных string destinationFilePath = @"C:\. . .\BinaryDataFile.bin"; byte[] dataCollection = { 1,
- 23. Чтение и запись двоичных данных string sourceFilePath = @"C:\. . .\BinaryDataFile.bin"; FileStream sourceFile = new FileStream(
- 24. Reading and writing Text Files We can use StreamReader and StreamWriter classes string filePath = "...";
- 25. Reading and Writing Text Files string sourceFilePath = @"C:\. . .\TextDataFile.txt"; // Create a FileStream object
- 26. Reading and Writing Text Files string sourceFilePath = @"C:\. . .\TextDataFile.txt"; string data; // Create a
- 27. Reading and Writing Text Files string destinationFilePath = @"C:\. . .\TextDataFile.txt"; string data = "Hello, this
- 29. Скачать презентацию