Using unityengine;
Using system. IO;
Using system;
Using system. collections;
Public class cgraettext: monobehaviour
{
Private string m_sfilename = "filename.txt"; // file name
Private string m_spath = application. persistentdatapath; // path
Private arraylist m_aarray; // content of each line in the text
/*
* Spath: directory for File Creation
* Sname: File Name
* Ndate: Data
*/
Void fncreatefile (string Spath, string sname, int ndate)
{
Streamwriter t_sstreamwriter; // file stream information
Fileinfo t_ffileinfo = new fileinfo (Spath + "//" + sname );
If (! T_ffileinfo.exists)
{
T_sstreamwriter = t_ffileinfo.createtext (); // if this file does not exist, create
}
Else
{
T_sstreamwriter = t_ffileinfo.appendtext (); // open the file if it exists.
}
T_sstreamwriter.writeline (ndate); // write information in the form of rows
T_sstreamwriter.close (); // close the stream.
T_sstreamwriter.dispose (); // destroy the stream
}
/*
* Path: the path to read the file.
* Name: name of the file to be read
*/
Arraylist fnloadfile (string Spath, string sname)
{
Streamreader t_sstreamreader = NULL; // read data in the form of a stream
// Try
//{
T_sstreamreader = file. opentext (Spath + "//" + sname );
//}
// Catch (exception ex)
//{
// Return NULL;
//}
String t_sline; // the content of each line
Arraylist t_javasraylist = new arraylist (); // container
While (t_sline = t_sstreamreader.readline ())! = NULL)
{
T_javasraylist.add (t_sline); // Save the content of each row to the array linked list container.
}
T_sstreamreader.close (); // close the stream
T_sstreamreader.dispose (); // destroy the stream
Return t_javasraylist; // return the array linked list container
}
/*
* Spath: Path of the file to be deleted
* Sname: name of the deleted object
*/
Void fndeletefile (string Spath, string sname)
{
File. Delete (Spath + "//" + sname );
}
}