일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- aduino
- digitalRead
- Encapusulation
- Pointer
- inheritance
- wpf
- mfc
- java
- Unity
- stream
- c++
- file access
- length
- Class
- UNO
- SERIAL
- Android
- flutter
- APP
- Read
- Barcode
- parameter
- Overloading
- sensor
- public
- Contour
- memory
- preprocessing
- atmega328
- compare
- Today
- Total
폴크(FOLC)
C# 테크닉 - 파일 제어( BIN format ) 본문
# WPF 를 이용하는 과정에서 HDD 에 존재하는 파일 ( binary format ) 제어
> Save, Load 형태 - List<Data> 형태 이용
> exe 파일 위치에 test.dat 파일 생성
# 소스 코드
using System.Runtime.Serialization.Formatters.Binary;
public class BINformat
{
[Serializable]
struct Data
{
public string key;
public string value;
public Data(string _key, string _value)
{
key= _key; value= _value;
}
}
public void WriteReadTest()
{
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
path = System.IO.Path.GetDirectoryName(path) + "\\test.dat";
List<Data> result;
List<Data> datalist = new List<Data>();
datalist.Add(new Data("11", "test1"));
datalist.Add(new Data("12", "test2"));
using (FileStream fs1 = new FileStream(path, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs1, datalist);
}
using (FileStream fs2 = new FileStream(path, FileMode.Open))
{
BinaryFormatter bf2 = new BinaryFormatter();
result = (List<Data>)bf2.Deserialize(fs2);
}
}
'C#, WF, WPF(.NET) > C#, WF, WPF(.NET) 테크닉' 카테고리의 다른 글
WPF 테크닉 - Chart 그리기 ( WPFToolkit ) (0) | 2021.12.03 |
---|---|
C# 테크닉 - 통신 Socket ( Client ) (0) | 2021.12.01 |
C# 테크닉 - 파일 제어( INI format ) (0) | 2021.11.29 |
C# 테크닉 - Page 전환 (0) | 2021.11.12 |
WPF 테크닉 - Page 전환 (0) | 2021.11.12 |