x


How do I create a text file and write data to it in javascript?

Hi all,

I need to write some data (just numbers and strings) to a text file that I can access once the game has stopped running. My 'game' is collecting data that is going to be used later in a different program, so player prefs isn't really an option (I think).

I'm using javascript, and I haven't been able to figure out how to create a new txt file, or even how to write to an already existing txt file. I have all my other code working; I just need a way to create a new txt file and then write or append strings to it.

I've been thinking that maybe some kind of http://File.IO command would do the trick, but nothing that I've tried seems to work so far.

more ▼

asked Feb 21 '12 at 05:56 PM

UTKev gravatar image

UTKev
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

sw = new StreamWriter("name of file.txt"); sw.Write("write you want: "); sw.WriteLine(item.name); //write and then give enter sw.Write("write you want: "); sw.WriteLine(Time.time); //If you want to save a variable sw.Close(); //Close the file

more ▼

answered May 21 at 10:30 AM

Marcelomacm gravatar image

Marcelomacm
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3464
x150
x56
x12
x7

asked: Feb 21 '12 at 05:56 PM

Seen: 848 times

Last Updated: 3 days ago