Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by Leocesar · Aug 05, 2012 at 07:27 AM · c#standalonemonotxt

Compatibility level and writing *.txt files

I am using a script to create a text file in “my documents” folder. It works perfectly while testing it in the Editor, but when I build and run the standalone it doesn’t work anymore.

Facts: 1) I use Unity free 2) API compatibility level in player preferences: .NET 2.0 (not subset) 3) There are no compilation errors or warnings

The funny thing is that my game also has scripts that use: System.IO; System.Reflection; and System.Runtime.Serialization; to create “save game files” and it works just fine.

What could be possibly going wrong? Here is the script to create *.txt files thank you in advance:

 using System;

using System.IO; using System.Text;

public class WriteTextFile { static string mydocpath; static string[] txtList; static StringBuilder sb = new StringBuilder ();

 public static void WriteFile ()
 {
     mydocpath = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
     txtList = Directory.GetFiles (mydocpath, "*.txt");        

     foreach (string txtName in txtList) {
         using (StreamReader sr = new StreamReader(txtName, Encoding.GetEncoding(1252))) {
             sb.AppendLine (txtName.ToString ());
             sb.AppendLine ("= = = = = =");
             sb.Append (sr.ReadToEnd ());
             sb.AppendLine ();
             sb.AppendLine ();
         }
     }   

     using (StreamWriter outfile = new StreamWriter (mydocpath + @"\AllTxtFiles.txt", false, Encoding.GetEncoding(1252))) {

         string temp = sb.ToString ();
         outfile.Write (temp);
     }
 }

}

Comment
Add comment · Show 3
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 ScroodgeM · Aug 05, 2012 at 11:16 AM 0
Share

add Debug.Log() to this method and check what happened and input prameters for correct data. also, did you already check the client's log after saving fails?

avatar image Bluk · Aug 05, 2012 at 12:27 PM 0
Share

Also I forgot to say, remember to close your streams ;)

avatar image Bunny83 · Aug 05, 2012 at 12:33 PM 1
Share

@Bluk: He uses "using". Since the Streams are IDisposable they should be recycled / freed when you leave the using block. Here's a nice example

1 Reply

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

Answer by Bluk · Aug 05, 2012 at 11:30 AM

You should have this exception in your output_log.txt in the standalone_name_Data folder:

 NotSupportedException: CodePage 1252 not supported
   at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unknown>:0 

It is due to a missing .dll

See here: http://answers.unity3d.com/questions/42955/codepage-1252-not-supported-works-in-editor-but-no.html

Cheers.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Audio Record Limit? 1 Answer

start/stop timer when a player enters/exits a room,start/stop timer when player enters/exits a room? 1 Answer

InvalidDataException not available? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges