我是新來的文件系統。我需要創建一個簡單的csv文件,並需要在文件中寫入字符串並將其讀回來。如何在C#中創建一個CSV文件#
我在創建的文件中獲得了一些unicode值。我如何通過創建csv並從中讀回來編寫字符串值。
到目前爲止,我已經寫了這個。這裏需要一點小屁股。
以下是我的代碼。
static void Main()
{
string folderName = @"D:\Data";
string pathString = System.IO.Path.Combine(folderName, "SubFolder");
System.IO.Directory.CreateDirectory(pathString);
string fileName = System.IO.Path.GetRandomFileName();
pathString = System.IO.Path.Combine(pathString, fileName);
Console.WriteLine("Path to my file: {0}\n", pathString);
if (!System.IO.File.Exists(pathString))
{
using (System.IO.FileStream fs = System.IO.File.Create(pathString))
{
{
byte a = 1;
fs.WriteByte(a);
}
}
}
// Read and display the data from your file.
try
{
byte[] readBuffer = System.IO.File.ReadAllBytes(pathString);
foreach (byte b in readBuffer)
{
Console.Write(b + " ");
}
Console.WriteLine();
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
}
}
你有沒有研究這個呢?這是一個簡單的任務,很可能有很多很多的例子。 –
問題到底是什麼? – HimBromBeere
@ rory.ap我試過了,但是我得到的文件中有不需要的值被創建 –