C#
2012.01.04 11:24

c# file i/o 샘플

조회 수 17070 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
  
using System;
using System.IO;

class WriteTextFile
{
    static void Main()
    {
        
        // These examples assume a "C:\Users\Public\TestFolder" folder on your machine.
        // You can modify the path if necessary.

        // Example #1: Write an array of strings to a file.
        // Create a string array that consists of three lines.
        string[] lines = { "First line", "Second line", "Third line" };
        System.IO.File.WriteAllLines(@"C:\price\WriteLines.txt", lines);
        
        
        // Example #2: Write one string to a text file.
        string text = "A class is the most powerful data type in C#. Like structures, " +
                       "a class defines the data and behavior of the data type. ";
        System.IO.File.WriteAllText(@"C:\price\WriteText.txt", text);
        
        // Example #3: Write only some strings in an array to a file.
        using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\price\WriteLines2.txt"))
        {
            foreach (string line in lines)
            {
                if (line.Contains("Second") == false)
                {
                    file.WriteLine(line);
                }
            }
        }

        // Example #4: Append new text to an existing file
        using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\price\WriteLines2.txt", true))
        {
            file.WriteLine("Fourth line");
        }
        
    }
}
/* Output (to WriteLines.txt):
    First line
    Second line
    Third line

 Output (to WriteText.txt):
    A class is the most powerful data type in C#. Like structures, a class defines the data and behavior of the data type.

 Output to WriteLines2.txt after Example #3:
    First line
    Third line

 Output to WriteLines2.txt after Example #4:
    First line
    Third line
    Fourth line
 */



Dreamy의 코드 스크랩

내가 모으고 내가 보는

List of Articles
번호 분류 제목 날짜 조회 수 추천 수
146 PHP GD 라이브러리 간단 2014.07.09 9469 0
145 Pi 라즈베리파이 PI CAMERA 설치하기 2018.04.24 9391 0
144 일반 사용하지 않는 COM Port 삭제하기 2015.03.18 9388 0
143 Android adb 를 이용한 터치 이벤트 보내기 2014.07.30 9371 0
142 일반 Html에서 사용하는 contentType의 종류 2015.10.27 9342 0
141 Pi ATTINY85 PIN정보, Data sheet 2 file 2016.12.10 9337 0
140 Pi 라즈베리파이를 크롬캐스트 처럼 사용하는 방법 - RaspiCast 2017.10.17 9221 0
139 Pi NodeMCU PIN 정보 file 2017.01.09 9154 0
138 C# Download Files from Web [C#] 2014.09.11 9153 0
137 LINUX 리눅스 명령행에서 메일 보내기(send mail from linux command line) 2019.11.25 9142 0
136 LINUX 명령어 뒤의 옵션 자동완성 기능, complete 명령어 2015.01.06 9022 0
135 LINUX epoch time을 실제 시간으로 변환해주는 excel 함수 2015.03.18 8993 0
134 Android ion memory 사용량 확인하기 2014.12.03 8964 0
133 Python json 데이터 핸들링 2017.03.09 8870 0
132 C++ istringstream 을 이용한 string type 변환 & 토크나이징 2017.06.07 8839 0
목록
Board Pagination ‹ Prev 1 ... 20 21 22 23 24 25 26 27 28 29 ... 34 Next ›
/ 34

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5