Blog Content

    티스토리 뷰

    [의뢰] openFileDialog 로 Text 텍스트 문서 읽어오기

    반응형

    텍스트문서(txt) 파일을 file Open으로 불러온 후 그 txt파일을 한글을 역으로 출력하는 예제를 알려주세요...

    라는 퀘스트를 받았습니다...정말 간단하게 만들었습니다.

    역으로...출력 하는 예제입니다.

    디자인 화면입니다.

    [그림1]

    입력하는 부분과 출력하는 부분을 만들어줬습니다.

    텍스트 박스에 입력을 하고 저장 버튼을 클릭하게 되면 텍스트 파일로 저장이 되고
    불러오기 버튼을 클릭하면 텍스트에 있는 내용을 거꾸로 출력되는 부분입니다. 


    전체 소스 입니다.

    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
    gg_Text
    {
        public partial class Form1 : Form
        {
            private string dir = Path.Combine(Application.StartupPath, "txtKor.txt");   //파일저장

            
    public Form1()
            {
                InitializeComponent();
            } 

            //저장
            private void btnOK_Click(object sender, EventArgs e)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(String.Format("{0}",txt1.Text));
                StreamWriter sw = new StreamWriter(dir, false, Encoding.Default);
                sw.WriteLine(sb.ToString());
                sw.Close();
                sw.Dispose();
                MessageBox.Show("저장");
            } 

            //불러오기
            private void btnLoad_Click(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.Default);

                    
    while (sr.Peek() >= 0)
                    {
                        string str = sr.ReadLine().ToString();
                        int i = str.Length-1;  

                        for (int j = 0; j <= str.Length - 1; j++)
                        {
                            if (i >= 0)
                            {
                                txtKorLoad.Text += str.Substring(i,1);
                                i--;
                            }
                        }
                    }
                }
            }
        }
    }


    테스트

    [그림2]



    [그림3]

     

    끝~

    gg_Text.zip

    반응형

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

    public private protected 차이  (0) 2015.11.01
    WPF RSS  (0) 2014.08.03
    Window PDA 입력,출력,수정,삭제,검색 기능  (0) 2010.09.14
    Window CE로 연결  (0) 2010.09.02
    33.C#_WinForm - C# Setup.exe 만들기  (10) 2009.09.08

    Comments