- Home /
Question by
AlaaMEbr · Oct 02, 2019 at 05:22 PM ·
androidandroid buildtext file
create a text file in my android device
I am working on a project where i want to create a text file on my android device and update it every time i open the app it works fine with win but when i build it on my device it didn't work ,didn't create text file but also there is no error
note: i already tried application.persistentdatapath but still the same
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class Main : MonoBehaviour {
void CreateText() {
//Path of the file
string path = Application.dataPath + "/Log.txt";
//Create File if it doesn't exist
if (!File.Exists(path)) {
File.WriteAllText(path, "Login log \r\r\n");
}
//Content of the file
string content = "Login date: \r\r\n";
//Add some to text to it
File.AppendAllText(path, content);
}
// Use this for initialization
void Start () {
CreateText();
}
// Update is called once per frame
void Update () {
}
}
What i am missing here?
Comment
I don't code for Andriod but maybe it is an issue with your path separator. It does differ depending on the platform. Try;
var path = Application.dataPath + Path.DirectorySeparatorChar + "Log.Txt";
Your answer
