这是我的页面的来源。我收到一个神秘的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();
}