StreamWriter类到字节_复制失败(溢出) [英] StreamWriter Class to Byte _ Failure to copy (OVERFLOW)

查看:86
本文介绍了StreamWriter类到字节_复制失败(溢出)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,伙计们,正在使用以下代码将一个文件复制到另一个文件,该文件是一个图像,但它不会将流转换为字节,并说算术操作导致溢出".在第18行中,有任何想法吗?

导入 System.IO
2
3 公共 Class Form1
4 私有 Sub Button1_Click ( ByVal 发件人 As 系统. 对象 ByVal e As System.EventArgs) 句柄 Button1.单击
6
7 t style ="font-size:11px"> mFile() 字节
8 > 新建 StreamReader( " c:\ s.bmp" )
9
10 Dim mDest As StreamWriter == 新建 StreamWriter( " c:\ p1.bmp" )
11
12
13 ="color:blue">昏暗 整数 i = mFile_Orig.Read()
15
16 (i) -1)
17
18 i = CByte (mFile_Orig.Read())
19
20 mDest.Write(i )
21 i = mFile_Orig.Read()
22
23
24 结束
25 mFile_Orig.Close ()
26
29 结束
30 结束
31

解决方案

在回答我不想使用System.IO.File类复制文件之前,请记住一下,我想监视文件的进度,因为它是逐字节进行的
...
所以请尝试通过相同的步骤帮助我我正在尝试
如果我使用Java尝试,它确实可以很好地运行
但是多数民众赞成在其他方面ss
java代码是:

FileOutputStream outputStream == new FileOutputStream ( " output.gif" ); FileInputStream inputinput = " input.gif" int next = inputStream.read(); 字节 (下一个!=- 1) { b ==( byte )next; outputStream.write(b); inputStream.close() ; outputStream.close();


hey guys, am using following code to copy one file to another and file is an image but it does not convert the stream to byte and says
"Arithmetic operation resulted in an overflow." in line 18, anyone having any idea?

1Imports System.IO 
2 
3Public Class Form1 
4 
5    Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
6 
7        Dim mFile() As Byte 
8        Dim mFile_Orig As StreamReader = New StreamReader("c:\s.bmp"
9 
10        Dim mDest As StreamWriter = New StreamWriter("c:\p1.bmp"
11 
12 
13        Dim i As Integer 
14        i = mFile_Orig.Read() 
15 
16        While (i <> -1) 
17           
18            i=CByte(mFile_Orig.Read()) 
19 
20            mDest.Write(i) 
21            i = mFile_Orig.Read() 
22 
23 
24        End While 
25        mFile_Orig.Close() 
26 
27        mDest.Close() 
28 
29    End Sub 
30End Class 
31 

解决方案

keep this in your mind before replying that i dont wanna use System.IO.File class to copy file, i wanna monitor files' progress as it goes byte by byte
...
so plz try helping me out with the same procedure i am trying
if i try it with java, it works really fine
but thats some other class
java code is:

    FileOutputStream outputStream = new FileOutputStream("output.gif"); 
    FileInputStream inputStream = new   FileInputStream("input.gif"); 
    int next = inputStream.read(); 
    byte b; 
    while (next != -1) 
     { 
       b = (byte)next; 
       outputStream.write(b); 
       next = inputStream.read(); 
     } 
    inputStream.close(); 
    outputStream.close(); 
 


这篇关于StreamWriter类到字节_复制失败(溢出)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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