예제 #1
0
 /// <summary>
 /// Write Property to node</summary>
 /// <param name="fileName">name of file. You must specify the extension of file, ".properties" is standard</param>
 /// <param name="nodeName">Name of the node you wish to test</param>
 /// <param name="nodeValue">Value of node you wish to write</param>
 public static void WriteNode(string fileName, string nodeName, string nodeValue)
 {
     if (String.IsNullOrWhiteSpace(fileName) || String.IsNullOrWhiteSpace(nodeName))
     {
         throw new Exception("Cannon have null string");
     }
     if (!File.Exists(fileName))
     {
         throw new FileNotFoundException(string.Format("File: \"{0}\" doesn't exist", fileName));
     }
     if (!NodeExists(fileName, nodeName))
     {
         throw new Exception("Node not found");
     }
     string[] lines = FileTools.ReadLinesFromFile(fileName);
     FileTools.ClearFile(fileName);
     for (int i = 0; i < lines.Count(); i++)
     {
         if (lines[i].Split('=')[0].Contains(nodeName))
         {
             lines[i] = string.Format("{0} = {1}", nodeName, nodeValue);
         }
         FileTools.WriteLineToFile(fileName, lines[i]);
     }
 }