加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

[VB.NET]问个关于internet收藏页的问题

发布时间:2020-12-16 23:40:06 所属栏目:大数据 来源:网络整理
导读:问个关于internet收藏页的问题 代码是: public class webfav public name as string public url as string public sub load(byval filename as string) dim strdata as stringt try strdata = my.computer.filesystem.readalltext(filename) 这里我不是很明
问个关于internet收藏页的问题 代码是: public class webfav public name as string public url as string public sub load(byval filename as string) dim strdata as stringt try strdata = my.computer.filesystem.readalltext(filename) 这里我不是很明白 catach ex as ioexception throw new exception(ioexception.message) end try =========================================== 书上的解释是: filename 代表收藏页的路径, 在我的计算机上是:“C:/Documents and Settings/Administrator/Favorites”,假设我的这个收藏页的文件名字是baidu.html 那么filename 的完整名称就是:“C:/Documents and Settings/Administrator/Favorites/baidu.html” ========================================== 然后书上有说: 读取文件后,strdata就包含类似于下面的数据: [default] baseurl= http://baidu.com [internetshortcut] url=http://baidu.com modified= xxxxxxxxxxxxxxxxxxx ========================================== 但是每次我按照书上写的代码访问这个文件的时候,老是提示找不到文件!!! 我的代码: strdata = my.computer.filesystem.readalltext( C:/Documents and Settings/Administrator/Favorites/baidu.html ) 请问这个是怎么回事啊, 希望高手帮我解决这个问题 谢谢大家 __________________________________________________________________________ baidu.html这个文件真的存在么,我看了一下,Favorites下存放的好像只是一些快捷方式。 __________________________________________________________________________ 打开摆渡,然后按ctrl+d,就会自动存储为收藏页, 默认的名字是:“百度一下,你就知道”,没有后缀 但是我书里写的是:“xxx.url” 所以我还以为要把后缀改成url才能用my.computer.filesystem.readalltext读他 这个真是搞不明白 应该怎么才好啊 __________________________________________________________________________ 书上说得没错,不用修改后缀的.这些文件的后缀不会显示,但其实是有的,就是 .url . 请看以下这段代码,它遍历了favorite文件夹中的文件,读取并显示其中的内容. Public Class Form1 Private Sub Form1_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load Dim strFiles() As String = IO.Directory.GetFiles( C:/Documents and Settings/Administrator/Favorites ) Dim strFile As String Dim strURL As String For Each strFile In strFiles MsgBox(strFile) If strFile.Contains( .url ) Then strURL = My.Computer.FileSystem.ReadAllText(strFile) MsgBox(strURL) End If Next End Sub End Class __________________________________________________________________________ LS的,你太帅了,为什么我写的代码就不行呢: Imports System.IO Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load Dim b As String = My.Computer.FileSystem.ReadAllText( Google ) End Sub End Class =================================== 提示找不到文件! 真是邪门了 能解释一下吗? 明白了就给分,谢谢你 __________________________________________________________________________ 错了,我写错了,应该是这样: Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load Dim b As String = My.Computer.FileSystem.ReadAllText( C:/Documents and Settings/Administrator/Favorites/Google ) End Sub End Class =================================== 但是还是提示找不到文件啊 __________________________________________________________________________ C:/Documents and Settings/Administrator/Favorites/Google 改为 C:/Documents and Settings/Administrator/Favorites/Google.url __________________________________________________________________________ 但是不要改变favorite文件夹下的文件名,这样应该能找到的。 __________________________________________________________________________ 请问这个My.Computer.FileSystem.ReadAllText中的ReadAllText不是只能读取TXT文件的吗? 而收藏页是url文件啊? 而且ReadAllText方法所读取的内容也不是URL文件的内容啊? 按照上面你的代码,显示的是 [default] baseurl= http://google.com [internetshortcut] url=http://google.com modified= xxxxxxxxxxxxxxxxxxx 但是我打开那个收藏页文件,却找不到这些内容 这个是怎么回事呢? __________________________________________________________________________ 你打开那个文件得到什么?我怎么都打不开。 __________________________________________________________________________ 不是只能读取TXT文件的,可以说是能读取文件中的文本,和文件本身的保存类型无关。 __________________________________________________________________________ 明白了 谢谢你 给分! __________________________________________________________________________

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读