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: 

解决方案 »

  1.   

    第二行:
    箱子2.0\bin\\Debug\\Map
    应改为:
    箱子2.0\\bin\\Debug\\Map
      

  2.   

    拼接字符串建议还是使用string.format.
      

  3.   

    这种问题 应该是路径你是直接复制到代码里出现的..我也遇到过很多次..很简单  d:\\1.txt   如果是手动敲上去的  就没问题.如果是从资源管理器 或者文件本身的路径复制过去的 就提示有问题..可能是系统编码的事吧.不过你这代码其实不应该写成固定目录 应该用var data=file.readallbytes(System.Windows.Forms.Application.StartupPath+"\\Map\\"+i+".info");来实现
      

  4.   

    你的ide已经告诉你了。它才是大神:路径中具有非法字符
    你把推箱子2.0\\推箱子2.0改成英文,然后2.0这种去掉。
      

  5.   

    改了还是有错误说有非法字符尝试在路径前面 加个  string filename = @"xxxxxx";
      

  6.   

    改了还是有错误说有非法字符
    C\\User......
    你这c盘路径明显不对啊。。
    人家都是  C:\
      

  7.   

    调试一下 filename 的值是什么?这个问题很简单,不应在这里多费口舌了。
      

  8.   

    错误提示:     在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)       在 推箱子2._0.Form1.ReadMap(Int32 n) 位
      

  9.   


    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;
                }