这是我的网页的来源。我得到一个神秘的CS1002错误。我已经看了一段时间了,还是不明白。
<%@ Page language="C#" validateRequest=false %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Threading" %>
<script language="C#" runat="server">
private void Page_Load (object sender, System.EventArgs e)
{
System.IO.Stream str; String strmContents;
Int32 counter, strLen, strRead;
// Create a Stream object.
str = Request.InputStream;
// Find number of bytes in stream.
strLen = Convert.ToInt32(str.Length);
// Create a byte array.
byte[] strArr = new byte[strLen];
// Read stream into byte array.
strRead = str.Read(strArr, 0, strLen);
writeFile(strArr, "images/test.png");
}
public void writeFile (byte[] data, String fileName)
{
FileStream out = new FileStream(fileName, FileMode.Open);
out.write(data);
out.close();
}
</script>
它在抱怨需要一个分号
Compiler Error Message: CS1002: ; expected
Line 24: FileStream out = new FileStream(fileName, FileMode.Open);
out
是一个关键字,我不认为你可以用它作为一个变量名。而不是尝试:
public void writeFile (byte[] data, String fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);
fs.write(data);
fs.close();
}
不能使用out,因为它是保留关键字。
http://msdn.microsoft.com/en-us/library/t3c3bfhx%28v=vs.71%29.aspx