- Home /
Question by
Vanidash-Studios · Oct 04, 2016 at 04:56 PM ·
textfilepath.txt
Cant append new line to an existing .txt file, instead it creates a completely new .txt file
Hello, so i am trying to create a character list inside a text file that has been created before when making an account, the problem that i am having is with my script, because it is creating a completely new text file with the character names, but i want them to be inside the account text file
here is the code: if (Charactername != "") { CN = true;
if (CN == true) {
charactername.GetComponent<InputField> ().text = "";
string createText = Charactername + Environment.NewLine;
//string [] charlist = {Charactername};
System.IO.File.WriteAllText(@"C:/UnityTestFolder/" + Username + ".txt", createText);
print ("Creation completed.");
}
`
Comment
Best Answer
Answer by flaviusxvii · Oct 04, 2016 at 05:02 PM
From the documentation for WriteAllText
"Creates a new file, write the contents to the file, and then closes the file. If the target file already exists, it is overwritten."
You probably want to use AppendAllText instead.
Your answer
![](https://koobas.hobune.stream/wayback/20220612094010im_/https://answers.unity.com/themes/thub/images/avi.jpg)