Forum Discussion
MrFlo666
5 years agoExplorer
How to read a csv file ?
Hello,
I develop under Unity 2019.3.8f1 in C# for an Oculus Quest.
I wish to read a csv file, parse it, and display stuff depending on the data contained inside the file.
Problem is :
1. I don't find my csv file inside the oculus quest (i checked with SideQuest)
2. I don't know which path to use to access it (once it will be uploaded and visible)
Can someone help me ?
Thanks !
I develop under Unity 2019.3.8f1 in C# for an Oculus Quest.
I wish to read a csv file, parse it, and display stuff depending on the data contained inside the file.
Problem is :
1. I don't find my csv file inside the oculus quest (i checked with SideQuest)
2. I don't know which path to use to access it (once it will be uploaded and visible)
Can someone help me ?
Thanks !
9 Replies
- rh_galaxyHeroic ExplorerIf the file is static you can include it in "unity_proj\Assets\Resources\custom_dir" rename it to .txt and access it through
TextAsset f = (TextAsset)Resources.Load("custom_dir/" + filename_no_extension);
String fileText = System.Text.Encoding.UTF8.GetString(f.bytes);
If it is a dynamic file maybeString fileText = System.Text.Encoding.UTF8.GetString(File.ReadAllBytes(Application.persistentDataPath + "/" + filename));
I use this to load text file level data, both default levels (at compile time), and custom levels (added dynamically later) in a Windows Desktop project, but it should work on the Quest as well. - MrFlo666ExplorerI'll check that but i already tried the dynamic solution, with no success. And I've taken a look at the files through SideQuest but didn't file my csv. Is there something specific I have to do on my project to make the csv files uploadable ?
- rh_galaxyHeroic ExplorerI don't know how the Quest works with files, but what path is the Application.persistentDataPath? Can you access that path and upload files to it from SideQuest?
But the static variant is sure to be working because then the file will be integrated to the package data at compile time and be transferred with the project when you upload the package. - MrFlo666Explorerlet's clarify something : what do you mean by "static" and "dynamic" ?
My need is that my csv files has to be installed in the same time than my apk. If it's the static variant you're talking about, then it's ok for me. If so, how to perform that ? - rh_galaxyHeroic ExplorerYes that's the meaning of static (compile time in the apk), dynamic (not known at compile time, not in apk but a file the user can upload at any time).
static: In your project path (on your PC), copy file to "\Assets\Resources\custom_dir" rename it to "file.txt" then in the codeTextAsset f = (TextAsset)Resources.Load("custom_dir/" + "file");then just parse the fileText string - it contains the whole .csv file.
String fileText = System.Text.Encoding.UTF8.GetString(f.bytes);char[] separator = { ',' };
string[] tokens = fileText.Split(separator, StringSplitOptions.RemoveEmptyEntries);
int first_value = int.Parse(tokens[0]);
... - MrFlo666Explorerok i'll check that, thanks !
just one question : why do i have to rename it into file.txt ? Is csv not allowed ? - rh_galaxyHeroic ExplorerGuess it's because you also access the file without the extension (just "file"), but the least confusing would just be to give the full file name and path all the time, so I don't really know the reason.
- MrFlo666Explorerok i'll check this afternoon and let you know. Thanks !
- MrFlo666Explorerhey hey, I confirm : this works well. Thanks for your precious help !
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 1 year ago
- 2 years ago