资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb点虐 大文件内容 vbnet filestream

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

'缓世歼唯扰冲区长度

四平ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!

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

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


分享标题:vb点虐 大文件内容 vbnet filestream
转载源于:http://cdkjz.cn/article/ddppdgo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220