0

This code works in my unity project by pressing play, but this code doesn't work when I build it, why?

void ReadString()
{
    string path = "Assets\\Turkey\\daglar.txt";
    FileStream akis = new FileStream(path, FileMode.Open, FileAccess.Read);
    StreamReader reader = new StreamReader(akis, Encoding.GetEncoding("iso-8859-9"), false);
    while (true)
    {
        dag = reader.ReadLine();

        if (dag != null)

            daglar.Add(dag);

        else break;
    }
    reader.Close();``
}
Ali kılıç
  • 11
  • 1
  • 1
  • 3
    Saying your code *doesn't work* is not helpful. You need to explain **why** it doesn't work. What output do you expect? What output are you getting? Error messages? Please put more effort into your posts. – DavidG Apr 02 '19 at 02:15
  • As @DavidG said, 'doesn't work' is too vague. Does the path not work? – Savaria Apr 02 '19 at 02:18
  • path is work but dag string looks empty – Ali kılıç Apr 02 '19 at 02:57
  • You probably have a similar [issue](https://stackoverflow.com/questions/55076189/how-can-i-use-c-sharp-code-in-unity-to-work-in-mobile/55076827#55076827) Also are you building for Android or Windows? – Ali Kanat Apr 02 '19 at 08:04
  • error is caused by this code` StreamReader reader = new StreamReader(path, Encoding.GetEncoding("iso-8859-9"),false);` but this code is necessary for the Turkish character problem,what should i do? – Ali kılıç Apr 02 '19 at 20:33
  • i build for windows – Ali kılıç Apr 16 '19 at 10:30

1 Answers1

-1

"Assets\Turkey\daglar.txt"; change to "Assets\Turkey\daglar.txt";

Why did you \ do 2 times?

saki
  • 174
  • 2
  • You cant use asset path. txt file move to StreamingAsset folder or any android folder – saki Apr 02 '19 at 02:54
  • You must create folder "Asset\StreamingAssets". txt file move to StreamingAssets folder. How to Access StreamingAsset folder is Application.streamingAssetsPath – saki Apr 02 '19 at 03:25
  • i tried this code but it didn't work string path = Application.streamingAssetsPath + "/sehirler.txt"; – Ali kılıç Apr 02 '19 at 18:25