using UnityEngine;
using System.Collections;
using System.IO;
public class TestCreateTxt : MonoBehaviour {
void OnGUI() {
if (GUI.Button(new Rect(Screen.width / Screen.width, Screen.height / Screen.height, 500, 20), "建立文件檔")) {
string[] lines = { "First line", "Second line", "Time line" };
File.WriteAllLines("C:/Users/user/Desktop/AAA.txt", lines);
string text = "A class is the most powerful data type in C#. Like a structure, " +
"a class defines the data and behavior of the data type. ";
File.WriteAllText("C:/Users/user/Desktop/TestTxt.txt", text);
StreamWriter file = new StreamWriter("C:/Users/user/Desktop/test2.txt");
foreach (string line in lines) {
if (!line.Contains("Second")) {
file.WriteLine(line);
}
}
}
}
}
結果圖:
沒有留言:
張貼留言