using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }
  
 

        //파일쓰기

        private void FileWrite(string str)
        {
            FileStream fs = new FileStream(str, FileMode.Append, FileAccess.Write);
            //FileMode중 append는 이어쓰기. 파일이 없으면 만든다.

            StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
            sw.WriteLine(str);
            sw.Flush();
            sw.Close();
            fs.Close();


        }

        private void button1_Click(object sender, EventArgs e)
        {
            FileWriteLine(@"C:\test\tes1t.txt"); //혹은 FileWriteLine("C:\\test\\tes1t.txt");
            FileWriteLine("ㅋㅋㅋ만세!");
        }

    }
}

FileWriteLine(@"C:\tes1t.txt"); <-error 남, C:\에서의 파일 쓰기 권한이 없어서 생기는듯...



출처 : http://egloos.zum.com/rapidme/v/5998041

'Programming > C#' 카테고리의 다른 글

변수 출력  (0) 2017.08.06
c# 동적으로 textbox 생성하기  (0) 2017.08.05
openFileDialog를 이용하여 파일읽기  (0) 2017.08.05
WinForm과 WPF  (0) 2017.07.02
윈폼(WinForm 의 구성요소, 생성코드)  (0) 2017.07.02

+ Recent posts