VS2015中VB.NET类(dLL)里下载并读取文件
2024-10-02 06:14:02
版权声明:未经允许禁止转载,否则会计入黑名单:http://www.cnblogs.com/123it/p/copyright.html
注意:已授权bilibili用户wy14abcd转载!
(已修改为VS(而不仅仅是VS2015))
最近要从一个http上下载个文件,差点就直接telnet了,突然发现了这个:
My.Computer.Network.DownloadFile("目标文件网址")
但是还得读取它,用什么呢?
直接用
Imports System.IO '引入System.IO命名空间
Dim test As New StreamReader("读取文件的路径")
但是在类里,不能用Application.StartupPath代表程序所在目录呀,这怎么办呢?遂baidu了一下,发现可以这样:
My.Application.Info.DirectoryPath '=Application.StartupPath
然后,就可以读取了。
完整代码:(目标文件地址http://123it.cf/test/download.txt)
Imports System.IO '引入System.IO命名空间 Public Class test Private Sub frm_test_Load(sender As Object, e As EventArgs) Handles MyBase.Load
My.Computer.Network.DownloadFile("http://123it.cf/test/download.txt", My.Application.Info.DirectoryPath & "\" & "down.txt") '下载文件
Dim rreeaadd As New StreamReader(My.Application.Info.DirectoryPath & "\" & "down.txt")
MsgBox(rreeaadd.ReadtoEnd,,"提示") '读取文件内容并弹出Msgbox消息框
rreeaadd.Close() '关闭流
End Sub End Class
最新文章
- 模仿iframe框架,由分隔栏动态改变左右两侧div大小———基于jQuery
- Linux 传输文件
- linuxMint設置窗口最大最小化
- 《深入浅出WPF》笔记一
- C#下调用C++ SDK的编码常识
- jQuery插件 -- 表单验证插件jquery.validate.js, jquery.metadata.js
- Girls: different perspectives to consider
- 20141109--SQL 练习题-1
- HTML5 Video与Audio 视频与音频
- http请求的cookie
- effective c++ 条款10 handle assignment to self operator =
- linux command----vi
- Ceph和Openstack的cinder模块对接方法
- OAuth授权 | 把这一篇丢给他
- Adversarial Examples for Semantic Segmentation and Object Detection 阅读笔记
- websocket 与 tornado 的结合
- OSWatcher使用过程中小问题解决方法
- 【2018.10.11 C与C++基础】C Preprocessor的功能及缺陷(草稿)
- RXD, tree and sequence IN HDU6065
- List进行排序