본문 바로가기
C#/수업내용

[ C# 10일차 ] 파일 입출력 File.WriteAllText(String, String), File.ReadAllText(String)

by 왹져박사 2023. 1. 13.
728x90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Study11
{
    class App
    {
        //생성자
        public App()
        {
            File.WriteAllText("./WriteAllText.txt", "새 파일을 만들고 이 문자열을 파일에 쓴 다음 파일을 닫는다!");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Study11
{
    class App
    {
        //생성자
        public App()
        {
            File.WriteAllText("./WriteAllText.txt", "새 파일을 만들고 이 문자열을 파일에 쓴 다음 파일을 닫는다!");

            string contents = File.ReadAllText("./WriteAllText.txt");
            Console.WriteLine(contents);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Study11
{
    class App
    {
        //생성자
        public App()
        {
            File.WriteAllText("./WriteAllText.txt", "새 파일을 만들고 이 문자열을 파일에 쓴 다음 파일을 닫는다!");

            string contents = File.ReadAllText("./WriteAllText.txt");
            Console.WriteLine(contents);

            if (File.Exists("./ReadAllText.txt"))
            {
                string contents0 = File.ReadAllText("./ReadAllText.txt");
                Console.WriteLine(contents0);
            }
            else
            {
                Console.WriteLine("파일이 없습니다. ");
            }
        }
    }
}

728x90