public Task <(bool, FileData)> GetFileDataFromPath(string filePath) { NSFileManager fileManager = NSFileManager.DefaultManager; if (fileManager.FileExists(filePath)) { NSFileHandle nSFileHandle = NSFileHandle.OpenRead(filePath); var fileData = nSFileHandle.AvailableData(); return(Task.FromResult((true, new FileData(filePath, Path.GetFileName(filePath), () => fileData.AsStream())))); } else { return(Task.FromResult <(bool, FileData)>((false, null))); } }
public void ReadFile() { try { // Gets the direct path to the file NSString folderPath = dataPath.AppendPathComponent(new NSString("testfile.txt")); // Handle the data and read it from the specific path NSFileHandle nsfh = NSFileHandle.OpenRead(folderPath); // Gets the data from the file NSData data = nsfh.ReadDataToEndOfFile(); string text = data.ToString(); } catch (Exception ex) { // Failed read data from a file } }
public Stream OpenRead(string filePath) { var path = filePath.Replace("\\", "/"); return(NSFileHandle.OpenRead(path).ReadDataToEndOfFile().AsStream()); }