我必须遗漏一些东西 - 没有意义的分号错误

时间:2011-10-12 17:35:27

标签: c# arrays filestream

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

2 个答案:

答案 0 :(得分:8)

out是关键字,我认为您不能将其用作变量名称。而是尝试:

public void writeFile (byte[] data, String fileName)
{
    FileStream fs = new FileStream(fileName, FileMode.Open);
    fs.write(data);
    fs.close();
}

答案 1 :(得分:-1)

你无法使用,因为它是保留关键字。

http://msdn.microsoft.com/en-us/library/t3c3bfhx%28v=vs.71%29.aspx