Question:Which of the following code samples will check if a file is in use? 

A protected virtual bool IsFileLocked(FileInfo file) { FileStream stream = null; try { stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch (IOException) { return true; } finally { if (stream != null) stream.Close(); } return false; } 

B try { using (Stream stream = new FileStream("MyFilename.txt", FileMode.Open)) { } } catch { } 

C internal static bool FileOrDirectoryExists(string name) { return (Directory.Exists(name) || File.Exists(name)) } 

D FileInfo file = new FileInfo("file.txt"); if (file.Exists) { // TO DO } 

+ Answer
+ Report
Total Preview: 724

Copyright © 2024. Powered by Intellect Software Ltd