- Home /
create text file in C#.
I've been searching for quite a while on this subject. And people tend to allways write in javascript here. I kinda have an idea of how this works. (this question helped me alot, but didnt answer how to write it in C#) I basicly want the same thing as this guy... But just in C#. Scriptrefference didnt help me either.
-thanks :) Link to my next question
Answer by CHPedersen · Jul 05, 2012 at 10:00 AM
You'll notice that I'm the one who replied to the link you posted, and I code in C#. ;)
The method I was using is still valid,
System.IO.File.WriteAllText("C:\blahblah_yourfilepath\yourtextfile.txt", "This is text that goes into the text file");
Is part of C#'s standard library, but you won't find this documented in the script reference, because it's not part of the Unity API, it's a standard .Net method. Look to MSDN for documentation on such. Here's the link, for your convenience:
You're welcome, I'm happy to help. :) (I edited the post multiple times for various typos...)
Now I just need to know... How do you read the text file you just created?... (The reason I need this, is because I need to transfer some variables from one scene to another. And i also have to save some variables like playerlevel and attached weapon and such...) I know this isnt a part of the question. But I thought you might also have the answer for this question :)
$$anonymous$$ake a new question, and we can continue our discussion in that. :) (This is so that others can find the answer on how to read from files if they search on google)
Answer by AlexTuduran · Aug 07, 2018 at 12:35 PM
And make sure to use "\\"
instead of "\"
for hard-coded paths. :)
Your answer
Follow this Question
Related Questions
,Block Levels and save progress 1 Answer
Playerprefs doesn't save anything. 2 Answers
Only able to save inside the editor problem 2 Answers
Save progress in WebGL game (C#) 1 Answer