我正在Visual Studio中开发一个应用程序,该应用程序可以读取和写入位于Visual Studio目录中的文件。如何访问visual studio中的本地目录项目中的文件
string creatureFile = @"\Resources\REGISTRADOS.DAT";
当我执行它,我得到一个FileNotFoundException异常 我希望帮助。
我正在Visual Studio中开发一个应用程序,该应用程序可以读取和写入位于Visual Studio目录中的文件。如何访问visual studio中的本地目录项目中的文件
string creatureFile = @"\Resources\REGISTRADOS.DAT";
当我执行它,我得到一个FileNotFoundException异常 我希望帮助。
这是我使用的代码: Func> ObtainCreatureList = ObtainCreatureListFromArray;
string[] creatureNameArray = fileManager.ReadFromFile(creatureFile);
IList<Creature> creatureList = ObtainCreatureList(creatureNameArray);
var villianList = from creature in creatureList
where creature.Name.Contains(villianIdentifier)
select new Creature
{
Name = creature.Name
};
// Write Villians to VILLIANS.DAT file
fileManager.WriteToFile(villiansFile, villianList.ToList());
Console.WriteLine("Press one key");
Console.ReadKey();
和文件管理器的代码是 公共字符串[] ReadFromFile(字符串路径) { 返回File.ReadAllLines(路径); }
public void WriteToFile(string path, IList<Creature> creatureCollection)
{
using (StreamWriter stream = File.AppendText(path))
{
foreach(var creature in creatureCollection)
{
stream.WriteLine(creature.Name);
}
}
}
不要发布其他信息作为答案 - **编辑**您原来的问题添加/更改的东西。 – Tim 2014-11-20 19:08:05
那行,你给我们** CAN NOT **抛出一个'fileNotFoundException',请出示实际的代码使用的是'creatureFile'与作为[编辑您的问题(HTTP:/ /stackoverflow.com/posts/27046858/edit) – 2014-11-20 18:28:35