일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- java
- parameter
- APP
- Android
- sensor
- Pointer
- inheritance
- Barcode
- preprocessing
- c++
- aduino
- SERIAL
- digitalRead
- Overloading
- Class
- length
- compare
- file access
- Contour
- Encapusulation
- memory
- Unity
- public
- UNO
- flutter
- Read
- stream
- mfc
- atmega328
- wpf
- Today
- Total
폴크(FOLC)
C# 테크닉 - 파일 제어( CSV format ) 본문
# WPF 를 이용하는 과정에서 HDD 에 존재하는 파일 ( csv format ) 제어
> Save, Load 형태 - StreamWriter, StreamReader 이용
> exe 파일 위치에 test.csv 파일 생성
# 소스 코드
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class CSVformat
{
struct CSVData
{
public string key;
public string value;
public CSVData(string _key, string _value)
{
_key= _key.Replace(",", " ");
_value= _value.Replace(",", " ");
key= _key; value= _value;
}
}
private List<CSVData> m_data = new List<CSVData>();
public void Save()
{
FileStream fs = File.Create("test.csv");
StreamWriter sw = new StreamWriter(fs, Encoding.Unicode);
foreach (CSVData dt in m_data)
{
sw.WriteLine("{0},{1}", dt.Col1, dt.Col2);
}
sw.Close();
fs.Close();
}
public void Load()
{
FileStream fs = File.OpenRead("test.csv");
StreamReader sr = new StreamReader(fs, Encoding.Unicode);
while (sr.EndOfStream == false)
{
string s = sr.ReadLine();
string[] sitems = s.Split(',');
m_data.Add(new CSVData(sitems[0], sitems[1]));
}
sr.Close();
fs.Close();
}
}
'C#, WF, WPF(.NET) > C#, WF, WPF(.NET) 테크닉' 카테고리의 다른 글
C# 테크닉 - FTP FileDownload ( WebRequest ) (0) | 2021.12.05 |
---|---|
C# 테크닉 - FTP FileUpload ( WebRequest ) (0) | 2021.12.05 |
WPF 테크닉 - Chart 그리기 ( LiveCharts ) (0) | 2021.12.03 |
WPF 테크닉 - Chart 그리기 ( WPFToolkit ) (0) | 2021.12.03 |
C# 테크닉 - 통신 Socket ( Client ) (0) | 2021.12.01 |