Search Unity

Android Directories with XML

Discussion in 'Android' started by mtewks, Jun 10, 2011.

  1. mtewks

    mtewks

    Joined:
    Jun 10, 2011
    Posts:
    82
    When saving and loading XML, will the way the directories are saved and loaded change based on the OS?
    I'm currently developing on Mac OSX and I got saving and loading working in Unity with XML, however when I run on the Android it no longer works.

    I suspect the way I handle the directories is the problem because I had to adjust them for the source code I found.
    Here's what I have that works on my Mac, but not on the Android as far as I can tell.

    Code (csharp):
    1. // Saves out the XML. Should not be called by anything except this class.
    2. private void CreateXML()
    3. {
    4.     // Mac Saves might work differently than on other computers. Look into it.
    5.     // "//" Might be needed for on Android
    6.     StreamWriter writer;
    7.     FileInfo t = new FileInfo(m_FileLocation + m_FileName);
    8.        
    9.     if(!t.Exists)
    10.         writer = t.CreateText();  
    11.     else
    12.     {
    13.         t.Delete();
    14.         writer = t.CreateText();
    15.     }
    16.    
    17.     writer.Write(m_data);
    18.     writer.Close();
    19.     Debug.Log("File written.");
    20. }
    21.    
    22. // Loads the XML. Should not be called by anything except this class.
    23. private void LoadXML()
    24. {
    25.     // Mac Loads differently. Other systems will want "//" possibly.
    26.     StreamReader r = File.OpenText(m_FileName);
    27.     string _info = r.ReadToEnd();
    28.     r.Close();
    29.     m_data = _info;
    30.     Debug.Log("File Read");
    31. }