私はエンコーディングの主題に不慣れで、より詳細に理解したいと思っています。フォルダーとファイルの作成に関するMSDNのこの例を見つけました。ファイルの作成は、WriteByte メソッドを使用して行われます。 http://msdn.microsoft.com/en-us/library/as2f1fez.aspx
便宜上、コードをすぐ下に配置しました。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CreateFolderFile
{
class Program
{
static void Main(string[] args)
{
// Specify a "currently active folder"
string activeDir = @"c:\testdir2";
//Create a new subfolder under the current active folder
string newPath = System.IO.Path.Combine(activeDir, "mySubDir");
// Create the subfolder
System.IO.Directory.CreateDirectory(newPath);
// Create a new file name. This example generates
// a random string.
string newFileName = System.IO.Path.GetRandomFileName();
// Combine the new file name with the path
newPath = System.IO.Path.Combine(newPath, newFileName);
// Create the file and write to it.
// DANGER: System.IO.File.Create will overwrite the file
// if it already exists. This can occur even with
// random file names.
if (!System.IO.File.Exists(newPath))
{
using (System.IO.FileStream fs = System.IO.File.Create(newPath))
{
for (byte i = 0; i < 100; i++)
{
fs.WriteByte(i);
}
}
}
// Read data back from the file to prove
// that the previous code worked.
try
{
byte[] readBuffer = System.IO.File.ReadAllBytes(newPath);
foreach (byte b in readBuffer)
{
Console.WriteLine(b);
}
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
}
// Keep the console window open in debug mode.
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
}
また、このテーマに関する Joel Spolsky による興味深い記事も見つけました。
すべてのソフトウェア開発者が絶対に、積極的に Unicode と文字セットについて知っておく必要がある絶対最小値 (言い訳はありません!) http://www.joelonsoftware.com/printerFriendly/articles/Unicode.html
私の質問: WriteByte メソッドで使用されるエンコーディングは何ですか? 私が行った読み取りから、何を使用しても、ファイルのエンコーディングを正確に判断することは本当に可能ですか? (例: 送信された csv ファイルで、メモ帳 ++ を使用してエンコードを決定します)。
考え?