protected void HandleLoad(string[] tokens) { if (tokens is null) { throw new ArgumentNullException(nameof(tokens)); } if (tokens.Length != 3) { writer.WriteLine("usage: load <address> <file>"); return; } int address; try { address = ParseInt(tokens[1]); } catch (FormatException) { writer.WriteLine($"Invalid address specified [{tokens[1]}]"); return; } string filePath = tokens[2]; if (!File.Exists(filePath)) { writer.WriteLine($"Cannot find file [{tokens[2]}]"); return; } if (address + filePath.Length >= memory.Size()) { writer.WriteLine($"Need larger memory to load this file at {tokens[1]}"); return; } try { byte[] fileContents = File.ReadAllBytes(filePath); foreach (var item in fileContents) { memory.WriteByte(address, item); address++; } } catch (IOException e) { writer.Write(e.StackTrace); } }