Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This code:</p> <pre><code> string[] iconfig = System.IO.File.ReadAllLines("config.cfg"); iuser = iconfig[0]; ipass = iconfig[1]; imem = iconfig[2]; iserver = iconfig[3]; </code></pre> <p>... will throw the exception you've talked about if the file contains fewer than 4 lines. Is that what's happening, perhaps? (You do talk about it creating a blank file.)</p> <p>Note that you're also opening the file with a <code>StreamReader</code> but for no purpose, given that you're also just calling <code>ReadAllLines</code> which will open it separately.</p> <p>When you write out the file with this code:</p> <pre><code>System.IO.StreamWriter configwrite = new System.IO.StreamWriter("config.cfg"); configwrite.WriteLine(outString); configwrite.Close(); </code></pre> <p>that's only writing out a single line, assuming <code>outString</code> doesn't contain any linebreaks... so I'm not sure how this could <em>ever</em> work, even in the IDE.)</p> <p>(Note that if you <em>do</em> want to use <code>StreamReader</code> and <code>StreamWriter</code>, you should use <code>using</code> statements so that the file handle gets closed even if there are exceptions. You don't need to use <code>StreamReader</code> or <code>StreamWriter</code> here though - you could use <code>File.WriteAllLines</code> or <code>File.WriteAllText</code>.)</p> <p>Finally, encryption should <em>not</em> be done over text. You will usually end up with garbled text which could easily contain invalid code units etc. Generally if you want to encrypt text, you convert it to binary, apply a <em>standard</em> encryption algorithm (don't write your own) and then if you want text out of it, you convert it to base64 with <code>Convert.ToBase64String</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload