Fly to the sky & Return

text file에 쓰기 & 읽기 본문

프로그래밍/c# & VB 등

text file에 쓰기 & 읽기

낼은어떻게 2023. 2. 6. 13:15
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
1
2
3
4
5
6
7
 if (printDialog1.ShowDialog() == DialogResult.OK)
    {
                label7.Text = printDialog1.PrinterSettings.PrinterName.ToString();
                StreamWriter sw = new StreamWriter(destFile1, false);
                sw.WriteLine(label7.Text);
                sw.Close();
    }
cs

 

1
2
3
4
5
6
7
8
 if (System.IO.File.Exists(destFile2))
    {
                string line;
                System.IO.StreamReader file = new System.IO.StreamReader(destFile2);
                line = file.ReadLine();
                label9.Text = line;
                file.Close();
    }
cs

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.IO;
 
namespace FileIOExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Write to a text file
            string[] lines = { "Line 1""Line 2""Line 3" };
            File.WriteAllLines("output.txt", lines);
 
            // Read from a text file
            string[] readLines = File.ReadAllLines("output.txt");
            Console.WriteLine("Contents of the text file:");
            foreach (string line in readLines)
            {
                Console.WriteLine(line);
            }
        }
    }
}
cs