0
byte[] bFileName = new byte[512];
r2Socket.Receive(bFileName);
String FileName = Encoding.UTF8.GetString(bFileName);
System.Windows.Forms.MessageBox.Show(FileName); // It's Ok. Show FileName = "text.jpg"

FileStream = new FileStream("D:\\" + FileName, FileMode.Create, FileAccess.Write);

文件流参数异常

path 是一个空字符串 (""),只包含空格,或者包含一个或多个无效字符。- 或 - path 指的是非文件设备,例如 NTFS 环境中的“con:”、“com1:”、“lpt1:”等。

为什么会发生?谢谢。

==

//CLIENT
byte[] bFileName = new byte[512];
Socket Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Socket.Connect(textBoxIP.Text, int.Parse(textBoxPORT.Text));
FileInfo sFileInfo = new FileInfo(textBoxFILE.Text);
string FileName = sFileInfo.Name;
bFileName = Encoding.UTF8.GetBytes(FileName);
Socket.Send(bFileName);
//SERVER
Socket rSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress rIPAddress = Dns.GetHostEntry("localhost").AddressList[0];
IPEndPoint rIPEndPoint = new IPEndPoint(IPAddress.Any, int.Parse(textBoxPORT2.Text));
rSocket.Bind(rIPEndPoint);
rSocket.Listen(1);
byte[] bFileName = new byte[512];
r2Socket.Receive(bFileName);
String FileName = Encoding.UTF8.GetString(bFileName);
4

1 回答 1

0

I'm going to guess it's because you are using UTF-8, and NTFS uses something else, thus the invalid characters error. I would try using another encoding.

Check out this SO post: What encoding are filenames in NTFS stored as?

于 2012-04-18T13:11:22.740 回答