如何下载 TXT 然后阅读? [英] How do I download a TXT and then read it?

查看:29
本文介绍了如何下载 TXT 然后阅读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我有一个程序应该从我的 Dropbox 下载一个只包含一个 URL 的 TXT 文件,将它保存在我的桌面上,然后像 Process.Start(DownloadedFile).

我的代码如下所示:

Dim path As String = "C:\Users\" &SystemInformation.UserName &\桌面"My.Computer.Network.DownloadFile("https://www.dropbox.com/s/uy9jpt1em3o6khp/download_location.txt?dl=1", path + "\" + "Download_Location" + ".txt")Dim fileReader 作为字符串fileReader = My.Computer.FileSystem.ReadAllText(path + "\Download_Location.txt")Process.Start(fileReader)

现在我的问题是,该程序确实下载了我的 txt 文件并正确命名了它.但是即使我知道文本文件中有文本,当程序下载它并将其保存在名为Download_Location.txt"的桌面上时,它也是空的.即使我 100% 确定应该有 URL 文本,下载的文件也不包含任何文本.

当我的程序到达 Process.Start(fileReader) 的代码时,它给了我一个错误:

<块引用>

由于未指定文件名,您无法启动进程.

非常感谢!很抱歉我的英语不好.

解决方案

当通过 URL 下载文件时,您需要使用直接 URL,因为您下载的正是您指定的 URL.您可以从 Web 浏览器下载它的原因是它首先从第一个链接加载页面,然后页面告诉浏览器重定向到实际文件.

通过 DropBox 的直接链接可通过 dl.dropboxusercontent.com 网站访问,这是获取文件直接链接所需的内容.DropBox 使用这个系统的原因可能是因为 dropbox.com/s/...dl.dropboxusercontent.com/content_link/...

话虽如此,请将您的下载网址从您现在拥有的网址切换为:https://dl.dropboxusercontent.com/content_link/Uxdm1CQxQ50LBm5QejnkGLOIXJf8QL2I‌ ui95XjhMUL2Wz4gjzBwiHttuA07RkbOl>code=work/p>

Okay so I have a program that is supposed to download a TXT file which ONLY contains a URL from my Dropbox, save it on my desktop, and then open the webbrowser like Process.Start(DownloadedFile).

My code looks like this:

Dim path As String = "C:\Users\" & SystemInformation.UserName & "\Desktop"
My.Computer.Network.DownloadFile("https://www.dropbox.com/s/uy9jpt1em3o6khp/download_location.txt?dl=1", path + "\" + "Download_Location" + ".txt")

Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(path + "\Download_Location.txt")
Process.Start(fileReader)

Now my problem is that, the program DOES download my txt file and name it correctly. But even if I know that there is text in the text file, when the program downloads it and saves it on my Desktop named "Download_Location.txt", it is empty. The downloaded file doesn't conatin any text even if Im 100% sure that there should be a URL text.

And when my program reached the code where Process.Start(fileReader) it gives me an error:

You can not start the process because no file name is specified.

Thanks a lot! And sorry for my bad english.

解决方案

When downloading files via a URL you are required to use a direct URL, due to that you download exactly the URL you specify. The reason you can download it from your web browser is because it first loads the page from the first link, then the page tells the browser to redirect to the actual file.

Direct links through DropBox are accessed via the dl.dropboxusercontent.com website, which is what you'll need to get the direct link to your file. The reason DropBox uses this system is probably because dropbox.com/s/... is yet a bit shorter than dl.dropboxusercontent.com/content_link/...

Having this said, switching your download URL from what you have now to: https://dl.dropboxusercontent.com/content_link/Uxdm1CQxQ50LBm5QejnkGLOIXJf8QL2I‌​ui95XjhMUL2Wz4gjzBwiHttuA07RkbOl/file?dl=1 should work.

这篇关于如何下载 TXT 然后阅读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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