When reading text file, I have an error about sharing violation in Unity3D
<p>I have some errors about IOException: Sharing violation.
My simulation program creates text file per 1/60s.
This code is written by Lua script.</p>

<p>This is Lua code. data.txt file is rewrite per 1/60s.
So, The content in file is changed per 1/60s. </p>

<pre><code>  function dataListener:post( t )
    --local fn = "data"
    local fn = "time"
    --local filename = fn.."_"..60*t..".txt"
    local filename = fn..".txt"
    local file = io.open(filename, "w+")


    --file:write(string.format("%d; %d; %d\n",x,y,z))
    --file:write("%d; %d; %d\n", xx, yy, zz)
    --file:write(xx/100," ", yy/100," ", zz/100," ", wxx/100," ", wyy/100," ", wzz/100," \n")
    file:write(60*t," \n")
    file:close()
  end
</code></pre>

<p>And Unity3D read this file in Update() function.</p>

<p>This is Unity3D C# code.</p>

<pre><code>using UnityEngine;
using System.Collections;
using System;
using System.IO;

public class Textparsing : MonoBehaviour
{
    public GUISkin skin;
    private int currentTextNumber;// text number


    string s;
    // Use this for initialization
    void Start()
    {
        currentTextNumber = 0;
        s = LoadTextFile("text/time.txt");
        print(s);
    }

    // Update is called once per frame
    void Update()
    {

        s = LoadTextFile("text/time.txt");
        print(s);
    }
    string LoadTextFile(string fileName)
    {
        string t = "";
        string line = "";
        StreamReader sr = new StreamReader(Application.dataPath + "/Resources/" + fileName);
        if (sr == null)
        {
            print("Error : " + Application.dataPath + "/Resources/" + fileName);
        }
        else
        {
            line = sr.ReadLine();
            while (line != null)
            {
                t += line;
                line = sr.ReadLine();
                if (line != null)
                {
                    t += "\n";
                }
            }
            sr.Close();
            // print("Loaded " + Application.dataPath + "/Resources/db/" + fileName);
        }
        return t;
    }

    //gui
    void OnGUI()
    {
        //read
        GUI.skin = skin;

        int halfW = Screen.width / 2;
        int halfH = Screen.height / 2;

        int x = 40;
        int y = halfH + 40;

        GUI.Label(new Rect(x, y, halfW * 1, halfH * 1.2f), s);
    }
}
</code></pre>

<p>In unity3D, This error occurs.</p>

<p>Error</p>

<pre><code>IOException: Sharing violation on path C:\Users\Public\Documents\Unity Projects\textparsing\Assets\Resources\text\time.txt
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:320)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
System.IO.File.OpenRead (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:363)
System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/StreamReader.cs:167)
System.IO.StreamReader..ctor (System.String path)
(wrapper remoting-invoke-with-check) System.IO.StreamReader:.ctor (string)
Textparsing.LoadTextFile (System.String fileName) (at Assets/Textparsing.cs:36)
Textparsing.Update () (at Assets/Textparsing.cs:29)
</code></pre>

<p>It is possible to read this file? or Is there any alternative method?</p>