首页后端开发ASP.NETvb点虐大文件内容 vbnet filestream

vb点虐大文件内容 vbnet filestream

时间2023-04-23 18:45:01发布访客分类ASP.NET浏览1274
导读:vb点虐 udpclient 发送大文件循环问题 '缓世歼唯扰冲区长度Const BufLen As Integer=800'包发送间隔Const Interval As Integer=62'缓冲区Dim buf As Byte( =No...

vb点虐 udpclient 发送大文件循环问题

'缓世歼唯扰冲区长度

Const BufLen As Integer=800

'包发送间隔

Const Interval As Integer=62

'缓冲区

Dim buf As Byte()=Nothing

'远程(目的)网络端点

Dim remoteep As IPEndPoint=Nothing

'如果你已将s定义为类的成员变量(实例或共享),注释掉下面这句

Dim s As UdpClient=Nothing

Dim willread As Integer

Try

buf=New Byte(BufLen-1) { }

s=New UdpClient()

' TextBox1.Text包含远程(目的)主机的IP地址

' TextBox2.Text包含远搜山冲程(目的)主机的端口号

remoteep=New IPEndPoint(IPAddress.Parse(Trim(TextBox1.Text)),CInt(TextBox2.Text))

' Label2.Text包含要发送的文件的路径

Using fs As New FileStream(Label2.Text,FileMode.Open,FileAccess.Read)

While fs.Positionfs.Length

willread=BufLen

If fs.Length-fs.PositionBufLen Then

willread=CInt(fs.Length-fs.Position)

End If

fs.Read(buf,0,willread)

s.Send(buf,willread,remoteep)

Thread.Sleep(Interval)

End While

End Using

Catch ex As Exception

MsgBox(ex.ToString())

Finally

If s IsNot Nothing Then

s.Close()

End If

End Try

VB点虐窗体设计中,如何读取.txt文件中的数据?

1、新建一个标准的VB EXE工程,只有一个Form,Form上有两个按钮:Command1和Command2。

2、双击Command1添加如下代码

Private Sub Command1_Click()

  Dim strFile     As String

  Dim intFile     As Integer

  Dim strData     As String

   strFile = "c:\学生成绩.txt"

  intFile = FreeFile

  Open strFile For Input As intFile

 行行缓 strData = StrConv(InputB(FileLen(strFile), intFile), vbUnicode)

  Debug.Print strData

  Close intFile

End Sub

3、按F8开始单步调试代码,点击Command1,进入单步调试功能,

4、多次按下F8或直接按下F5运行完成,带茄就完成了读取文本文件内容并输出档模到立即窗口。

求大神指点 vb点虐 怎么发送大文件 我用 UdpClient 的Send只能发送5000字节以下的

下载,直接通过url读取文件,然后Response.OutputStream.Write()数据

下面提供个下载的静态方法,是C#的,供参考:

/// summary

/// 下载文件

/// /summary

/// param name="fileName"下载行颤斗的文件名称(包括扩展名)/param

/// param name="filePath"下载文件的绝对路径/param

public static void DownFile(string fileName, string filePath)

{

    //打开要下载的文件,并把该文件存放在FileStream中        档磨        

    System.IO.FileStream Reader = System.IO.File.OpenRead(filePath);

    //文件传送的剩余字节数:初始值为文件的总大小                

    long Length = Reader.Length;

    HttpContext.Current.Response.Buffer = false;

    HttpContext.Current.Response.AddHeader("Connection", "Keep-Alive");

    HttpContext.Current.Response.ContentType = "application/octet-stream";

    HttpContext.Current.Response.Charset = "utf-8";

    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;  filename=" + System.Web.HttpUtility.UrlEncode(fileName));

    HttpContext.Current.Response.AddHeader("Content-Length", Length.ToString());

    byte[] Buffer = new Byte[10000]; //存放欲发送数据的缓冲区                

    int ByteToRead;  //每次实际读取的字节数               

    while (Length  0)

   洞枣 {     

 //剩余字节数不为零,继续传送                    

        if (HttpContext.Current.Response.IsClientConnected)

        {     

//客户端浏览器还打开着,继续传送                        

            ByteToRead = Reader.Read(Buffer, 0, 10000);                    //往缓冲区读入数据                        

            HttpContext.Current.Response.OutputStream.Write(Buffer, 0, ByteToRead);     

//把缓冲区的数据写入客户端浏览器                        

            HttpContext.Current.Response.Flush();  //立即写入客户端                        

            Length -= ByteToRead; //剩余字节数减少                            }

        else

        {                          

//客户端浏览器已经断开,阻止继续循环                        

            Length = -1;

        }

    }                 //关闭该文件               

    Reader.Close();

}

易语言 / VB.NET 如何获取大文件的尺寸(>4GB) 在易语言环境下无法用“取文件尺寸(F

把结果用字节集变量,再其字节集数据,长整数就行了,多大都能取

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: vb点虐大文件内容 vbnet filestream
本文地址: https://pptw.com/jishu/6548.html
java代码过滤全字符 java 过滤特殊字符 小项目代码java java 小项目

游客 回复需填写必要信息