Hi all, I am attempting to export strings to a text file but it isn’t working and this has been a major road block in my app development. I’ve tried everything possible but it just isn’t working. What I am trying to do is to get the path file, create a new directory/folder called “textFiles” and then export the .txts into the textFiles folder.
I have a textmesh that tells me what the Application.persistentDataPath is, and it comes out to /data/data/com.app.app/files. With the create directory code, the new path should be /data/data/com.app.app/files/textFiles, but this clearly isn’t the case…
Further more, when I plug my phone into the computer and go to this directory, it comes out to \Android\data\com.app.app\files. Why is there no second data directory?? (data/data)
After doing some research, some people say that this second data directory is hidden, which makes no sense.
Also, I am strictly limiting this to internal storage. No SD card or external write accesses.
I believe the issue might be that the directory and text file are being created but I am not able to view it. I really can’t hardcore paths because each phone is different, I need to use the persistent data path.
The reason I need a text file is because I am making an app that takes in reports, and I would like to export these reports as text files so people may copy and paste the information into any appropriate program.
Any help would be appreciated, thanks!!!
#pragma strict
import System;
import System.IO;
private var createDirectory : String;
function Awake() {
createDirectory = Application.persistentDataPath + "/textFiles";
}
function OnMouseDown() {
var clickedTag:String = this.gameObject.tag; //variable for object tag
if(clickedTag == "reportTXT"){
if (!Directory.Exists (createDirectory)) {
Directory.CreateDirectory(createDirectory);
}
else {
var sr = new File.CreateText(createDirectory + "/MyFile.txt");
sr.Write("KUSH");
sr.WriteLine ("This is my file.");
sr.WriteLine ("I can write ints {0} or floats {1}, and so on.",
1, 4.2);
sr.Close();
}
}
}