• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Catlard · Nov 04, 2011 at 01:50 PM · text.netdeletetxt.txt

Modifying a text file outside unity.

Hey, so I've got some code that creates a text file with some player data in it, but I can't figure out how to either:

a)modify a value in the text file, or alternatively b)delete the text file so I can rewrite it with new values.

Here's the function I'm attempting to write:

 function updatePlayerData()
 {
     Delete(docPath); //this line throws an error.
     var sr = File.CreateText(docPath); 
     for(var i=0; i< playerInfoRealArray.length; i++)
     {
          sr.WriteLine (playerInfoRealArray[i]);
     }
     Debug.Log("Updated the player's data.");
     sr.Close(); 
 }


Any idea how to do it?

Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DaveA · Nov 04, 2011 at 02:53 PM

http://msdn.microsoft.com/en-us/library/system.io.file.aspx

Check that the file exists with File.Exists and delete with File.Delete. To modify, you have to read the file (into strings if that's what you're doing), modify them, then write it out.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Catlard · Nov 04, 2011 at 02:57 PM 0
Share

Thanks! You're a pal. I'll just delete the crap out of the file, as it's more relaxing to start afresh.

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

text to speech in webplayer 0 Answers

Set String Array or List to .txt File in a Builds Data Folder 2 Answers

DirectoryNotFoundException when running a build 1 Answer

Read txt file from Android Downloads file 1 Answer

WWW request works in Editor but not in IOS? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges