Stream不支持写作 [英] Stream does not support writing

查看:163
本文介绍了Stream不支持写作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我有一个程序而且我遇到了一些错误。

Excuse me, I have a program and I got some error. there Is error in "

cs.Write(bytBuffer, 0, intBytesInCurrentBlock)

'Stream不支持写入。请帮我学习。谢谢,抱歉我的英语不好。



我尝试过的事情:



" 'Stream does not support writing. Please help me for my studying. thank you, sorry for my bad English.

What I have tried:

Private Sub enkripataudekrip(ByVal inputfile As String, ByVal outputfile As String, ByVal secret As String, ByVal direction As aksikripto)

        Dim fsinput As New FileStream(inputfile, FileMode.Open, FileAccess.Read)
        Dim fsoutput As New FileStream(outputfile, FileMode.OpenOrCreate, FileAccess.Write)
        fsoutput.SetLength(0)
        Dim skey As String = "aaaaaaaa"
        Dim bytBuffer(4096) As Byte 'holds a block of bytes for processing
        Dim lngBytesProcessed As Long = 0 'running count of bytes processed
        Dim lngFileLength As Long = fsinput.Length 'the input file's length
        Dim intBytesInCurrentBlock As Integer 'current bytes being processed
        Dim cs As CryptoStream
        Dim des As New DESCryptoServiceProvider
        des.Key = ASCIIEncoding.ASCII.GetBytes(skey)
        des.IV = ASCIIEncoding.ASCII.GetBytes(skey)
        Select Case direction
            Case aksikripto.enkrip
                

                cs = New CryptoStream(fsoutput, des.CreateEncryptor, CryptoStreamMode.Write)
                'Dim bytearrayinput(fsinput.Length - 1) As Byte
                'fsinput.Read(bytearrayinput, 0, bytearrayinput.Length)
                'cs.Write(bytearrayinput, 0, bytearrayinput.Length)
                'cs.Close()

            Case aksikripto.dekrip
                'Dim des As New DESCryptoServiceProvider
                cs = New CryptoStream(fsinput, des.CreateDecryptor, CryptoStreamMode.Read)

                'Dim fsdekrip As New StreamWriter(outputfile)
                'fsdekrip.Write(New StreamReader(csdec).ReadToEnd)
                'fsdekrip.Flush()
                'fsdekrip.Close()
        End Select

        While lngBytesProcessed < lngFileLength
            intBytesInCurrentBlock = fsinput.Read(bytBuffer, 0, 4096)
            cs.Write(bytBuffer, 0, intBytesInCurrentBlock) 'Stream does not support writing

        End While

        cs.Close()
        fsinput.Close()
        fsoutput.Close()

    End Sub

推荐答案

根据读取或写入的方向创建cs作为读取或写入cryptuffream,然后写入cs,无论是读取还是写入操作,可能是读取的版本cs无法写。
You create cs as a read or write cryptostream based on the direction read or write, you then write to cs regardless of whether it is a read or write operation, likely the read version of cs cannot write.


这篇关于Stream不支持写作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆