_EagleOwle_

RuntimeText

Aug 23rd, 2021 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System.IO;
  2. using UnityEngine;
  3.  
  4. public class RuntimeText : MonoBehaviour
  5. {
  6.     public static void WriteString()
  7.     {
  8.         string path = Application.persistentDataPath + "/test.txt";
  9.         //Write some text to the test.txt file
  10.         StreamWriter writer = new StreamWriter(path, true);
  11.         writer.WriteLine("Test");
  12.         writer.Close();
  13.         StreamReader reader = new StreamReader(path);
  14.         //Print the text from the file
  15.         Debug.Log(reader.ReadToEnd());
  16.         reader.Close();
  17.     }
  18.     public static void ReadString()
  19.     {
  20.         string path = Application.persistentDataPath + "/test.txt";
  21.         //Read the text from directly from the test.txt file
  22.         StreamReader reader = new StreamReader(path);
  23.         Debug.Log(reader.ReadToEnd());
  24.         reader.Close();
  25.     }
  26. }
  27.  
Add Comment
Please, Sign In to add comment