개발 관련/SW, App 관련

(과거게시물) Unity3D file write and read,,, 파일 읽고 쓰기(stream이용)

by 소서리스25 2023. 3. 28.
반응형

※ 과거 게시물은 현재의 모든 적용사항과 환경이 다를 수 있으며 단순한 기록으로 남깁니다.

 

Unity3D file write and read,,, 파일 읽고 쓰기(stream이용)

 

내 입맛에 바꿨는데... 예전에 했던거 보다 잘되네..

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
private string filepath = "c:\\data.txt";
 
void Start () 
{
    StartCoroutine(sendstring());
}
 
IEnumerator reset()
{
  yield return new WaitForSeconds(3);
  txtInput.text = "";
}
 
IEnumerator sendstring()
{
    yield return new WaitForSeconds(3);
    writeFile(filepath);
    yield return new WaitForSeconds(2);
    readFile(filepath);
}
 
void writeFile(string writeData)
{
    StreamWriter wr = new StreamWriter(writeData);
    wr.WriteLine("tipon, 000000000");
    wr.WriteLine("ponpon, 3333333");
    wr.WriteLine("ponpon, 3333333");
    wr.Flush();
    wr.Close();
}
 
void readFile(string readData)
{
    StreamReader rd = new StreamReader(readData);
 
    string line="";
 
    while(true)
    {
           line = rd.ReadLine();
 
        if(line == nullbreak;
 
       print("sting : "+line);
      }
 
  rd.Close();
}
cs

 

반응형

댓글