string filename = "C\\Users\\13374\\Documents\\VisualStudio2015\\Projects\\推箱子2.0\\推箱子2.0\bin\\Debug\\Map" + n.ToString() + ".info";
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);未处理System.ArgumentException HResult=-2147024809 Message=路径中具有非法字符。 Source=mscorlib StackTrace: 在 System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional) 在 System.IO.Path.GetFileName(String path) 在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) 在 推箱子2._0.Form1.ReadMap(Int32 n) 位置 C:\Users\13374\Documents\Visual Studio 2015\Projects\推箱子2.0\推箱子2.0\Form1.cs:行号 36 在 推箱子2._0.Form1.initdata() 位置 C:\Users\13374\Documents\Visual Studio 2015\Projects\推箱子2.0\推箱子2.0\Form1.cs:行号 53 在 推箱子2._0.Form1.Form1_Load(Object sender, EventArgs e) 位置 C:\Users\13374\Documents\Visual Studio 2015\Projects\推箱子2.0\推箱子2.0\Form1.cs:行号 58 在 System.Windows.Forms.Form.OnLoad(EventArgs e) 在 System.Windows.Forms.Form.OnCreateControl() 在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 在 System.Windows.Forms.Control.CreateControl() 在 System.Windows.Forms.Control.WmShowWindow(Message& m) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.ScrollableControl.WndProc(Message& m) 在 System.Windows.Forms.Form.WmShowWindow(Message& m) 在 System.Windows.Forms.Form.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) InnerException:
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);未处理System.ArgumentException HResult=-2147024809 Message=路径中具有非法字符。 Source=mscorlib StackTrace: 在 System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional) 在 System.IO.Path.GetFileName(String path) 在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) 在 推箱子2._0.Form1.ReadMap(Int32 n) 位置 C:\Users\13374\Documents\Visual Studio 2015\Projects\推箱子2.0\推箱子2.0\Form1.cs:行号 36 在 推箱子2._0.Form1.initdata() 位置 C:\Users\13374\Documents\Visual Studio 2015\Projects\推箱子2.0\推箱子2.0\Form1.cs:行号 53 在 推箱子2._0.Form1.Form1_Load(Object sender, EventArgs e) 位置 C:\Users\13374\Documents\Visual Studio 2015\Projects\推箱子2.0\推箱子2.0\Form1.cs:行号 58 在 System.Windows.Forms.Form.OnLoad(EventArgs e) 在 System.Windows.Forms.Form.OnCreateControl() 在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 在 System.Windows.Forms.Control.CreateControl() 在 System.Windows.Forms.Control.WmShowWindow(Message& m) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.ScrollableControl.WndProc(Message& m) 在 System.Windows.Forms.Form.WmShowWindow(Message& m) 在 System.Windows.Forms.Form.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) InnerException:
箱子2.0\bin\\Debug\\Map
应改为:
箱子2.0\\bin\\Debug\\Map
你把推箱子2.0\\推箱子2.0改成英文,然后2.0这种去掉。
C\\User......
你这c盘路径明显不对啊。。
人家都是 C:\
try
{
int n = 1;
//string filename = @"C:\\Users\\13374\\Documents\\VisualStudio2015\\Projects\\推箱子2.0\\推箱子2.0\bin\\Debug\\Map" + n.ToString() + ".info";
string filename = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, $"Map{ n.ToString()}.info");
//string filename = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Map" + n.ToString() + ".info");
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
BinaryReader r = new BinaryReader(fs);
}
}
catch (Exception ex)
{ throw;
}