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:
uj5u.com熱心網友回復:
第二行:箱子2.0\bin\\Debug\\Map
應改為:
箱子2.0\\bin\\Debug\\Map
uj5u.com熱心網友回復:
拼接字串建議還是使用string.format.uj5u.com熱心網友回復:
這種問題 應該是路徑你是直接復制到代碼里出現的..我也遇到過很多次..很簡單 d:\\1.txt 如果是手動敲上去的 就沒問題.
如果是從資源管理器 或者檔案本身的路徑復制過去的 就提示有問題..
可能是系統編碼的事吧.
不過你這代碼其實不應該寫成固定目錄 應該用
var data=https://bbs.csdn.net/topics/file.readallbytes(System.Windows.Forms.Application.StartupPath+"\\Map\\"+i+".info");
來實作
uj5u.com熱心網友回復:
你的ide已經告訴你了。它才是大神:路徑中具有非法字符你把推箱子2.0\\推箱子2.0改成英文,然后2.0這種去掉。
uj5u.com熱心網友回復:
改了還是有錯誤說有非法字符
uj5u.com熱心網友回復:
嘗試在路徑前面 加個 string filename = @"xxxxxx";
uj5u.com熱心網友回復:
你的ide已經告訴你了。它才是大神:路徑中具有非法字符
你把推箱子2.0\\推箱子2.0改成英文,然后2.0這種去掉。
改了還是有錯誤說有非法字符
C\\User......
你這c盤路徑明顯不對啊。。
人家都是 C:\
uj5u.com熱心網友回復:
要不我把代碼發你幫我看一下uj5u.com熱心網友回復:
改了,加上@后直接找不到檔案了uj5u.com熱心網友回復:
第二行:
箱子2.0\bin\\Debug\\Map
應改為:
箱子2.0\\bin\\Debug\\Map
不是這個的問題,這個改了沒用
uj5u.com熱心網友回復:
除錯一下 filename 的值是什么?這個問題很簡單,不應在這里多費口舌了。uj5u.com熱心網友回復:
錯誤提示: 在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) 在 推箱子2._0.Form1.ReadMap(Int32 n) 位uj5u.com熱心網友回復:
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;
}
uj5u.com熱心網友回復:
問一下,你這info中內容是啥樣的?轉載請註明出處,本文鏈接:https://www.uj5u.com/net/85031.html
標籤:C#
