A
A
Andrey2021-12-29 16:11:33
Android
Andrey, 2021-12-29 16:11:33

How to work with files in StreamingAssets?

The Unity project is implemented for android. I put the files in the StreamingAssets folder in the Assets folder. I write the path to the file:

fileName = "jar:file://" + Application.dataPath + "!/assets/" + "questions.txt"


I'm trying to write a certain string to an object on the stage through a function:
public void ReadFile (string filename, int numberQuestion) {
        using (StreamReader reader = File.OpenText(filename))
        {
            string line = null;

            for (int i = 0; i <= numberQuestion; i++) {
                line = reader.ReadLine();  
                questionText.GetComponent<Text>().text = line;

            }
        }

    }


But doesn't work. Although, by specifying a relative path and running from the computer, it worked.
What's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2021-12-29
@andreyfilippov3001

And in general, text data can be accessed in resources as TextAssetwell as not having trouble with files.

G
GavriKos, 2021-12-29
@GavriKos

On android, you need to work with streaming assets through UnityWebRequest. And it is not at all necessary to form the path in this way - dataPath will already seem to contain an appendix in the form of a jar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question