System.IO.DirectoryNotFoundException异常代码:
using System;
using System.IO;
using System.Text;class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt"; // Delete the file if it exists.
if (File.Exists(path))
{
File.Delete(path);
} //Create the file.
using (FileStream fs = File.Create(path))
{
AddText(fs, "This is some text");
AddText(fs, "This is some more text,");
AddText(fs, "\r\nand this is on a new line");
AddText(fs, "\r\n\r\nThe following is a subset of characters:\r\n"); for (int i=1;i < 120;i++)
{
AddText(fs, Convert.ToChar(i).ToString()); //Split the output at every 10th character.
if (Math.IEEERemainder(Convert.ToDouble(i), 10) == 0)
{
AddText(fs, "\r\n");
}
}
} //Open the stream and read it back.
using (FileStream fs = File.OpenRead(path))
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
}
} private static void AddText(FileStream fs, string value)
{
byte[] info = new UTF8Encoding(true).GetBytes(value);
fs.Write(info, 0, info.Length);
}
}
========================未处理的异常: System.IO.DirectoryNotFoundException: 未找到路径“c:\temp\MyTest.
txt”的一部分。
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFr
omProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize)
at System.IO.File.Create(String path)
at Test.Main() in d:\visual studio projects\file与text实例程序\consoleapplica
tion1\class1.cs:line 19
using System;
using System.IO;
using System.Text;class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt"; // Delete the file if it exists.
if (File.Exists(path))
{
File.Delete(path);
} //Create the file.
using (FileStream fs = File.Create(path))
{
AddText(fs, "This is some text");
AddText(fs, "This is some more text,");
AddText(fs, "\r\nand this is on a new line");
AddText(fs, "\r\n\r\nThe following is a subset of characters:\r\n"); for (int i=1;i < 120;i++)
{
AddText(fs, Convert.ToChar(i).ToString()); //Split the output at every 10th character.
if (Math.IEEERemainder(Convert.ToDouble(i), 10) == 0)
{
AddText(fs, "\r\n");
}
}
} //Open the stream and read it back.
using (FileStream fs = File.OpenRead(path))
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
}
} private static void AddText(FileStream fs, string value)
{
byte[] info = new UTF8Encoding(true).GetBytes(value);
fs.Write(info, 0, info.Length);
}
}
========================未处理的异常: System.IO.DirectoryNotFoundException: 未找到路径“c:\temp\MyTest.
txt”的一部分。
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFr
omProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize)
at System.IO.File.Create(String path)
at Test.Main() in d:\visual studio projects\file与text实例程序\consoleapplica
tion1\class1.cs:line 19
txt”的一部分。
不是说的很清楚了?
是第19行的问题?应该怎么解决啊?
{
StreamWriter SW;
SW=File.CreateText("c:\\shiyan.txt");
SW.WriteLine("123");
SW.WriteLine("345");
SW.Close();
}我晕,这个代码也有同样的异常。。什么意思嘛高人在哪
public static void Main()
{
WriteToFile();
}
static void WriteToFile()
{
StreamWriter SW;
SW=File.CreateText("c:\MyTextFile.txt");
SW.WriteLine("God is greatest of them all");
SW.WriteLine("This is second line");
SW.Close();
Console.WriteLine("File Created SucacessFully");
}
}是不是我的.netframwork的版本问题???我崩溃了快
找不到类型或命名空间名称“MessageBoxOptions”(是否缺少 using 指令或程序集引用?)
这是因为智能设备模块本身的bug,还是因为我的点net有问题呢???