Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
data.txtソリューションに埋め込まれたテキスト ファイルがあります(この SO の質問で説明されているように)。
data.txt
このファイルの内容を文字列として読み取るにはどうすればよいですか? 私は次のようなものを想像しています:
string data = Resources["data.txt"];
しかし、それはそれを行う方法ではありません。
ファイルをリソースとして追加すると、次のようにアクセスできるはずです。
Properties.Resources.data
または、Copy to Output DirectoryプロパティをCopy always/Copy if newerに設定すると、次のようなことができます。
Copy to Output Directory
Copy always
Copy if newer
using (FileStream fs = System.IO.File.Open("Resources/data.txt", FileMode.Open)) { // do amazing stuff here ... }