从互联网上的txt文件中获取文本 [英] Get text from txt file on the internet

查看:37
本文介绍了从互联网上的txt文件中获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 uwp,我需要将保存在 Internet 上的 txt 文件中的文本转换为字符串 我在下载文件并将文本转换为字符串时遇到问题

I have a uwp and i need to get text from a txt file saved on the internet to string I have a problem with download the file and get the text to string

这是我的代码:

            var webRequest = WebRequest.Create(@"http://yourUrl");
        using (var response = webRequest.GetResponse())
        using (var content = response.GetResponseStream())
        using (var reader = new StreamReader(content))
        {
            var strContent = reader.ReadToEnd();
        }

有人可以帮我吗?

推荐答案

我找到了问题的答案

我必须将txt文件下载到本地存储,然后从本地读取它们

I've to download the txt file to my local storage and after that i read them from my local

这是我用来将文件下载到本地文件夹的代码

Here's the code that i used to download the file to my local folder

            var uriBing = new Uri(@"https://your/abc.txt");
        StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
        StorageFile sampleFile = await storageFolder.CreateFileAsync("status.txt", CreationCollisionOption.ReplaceExisting);
        var cli = new HttpClient();
        Byte[] bytes = await cli.GetByteArrayAsync(uriBing);
        IBuffer buffer = bytes.AsBuffer(); await Windows.Storage.FileIO.WriteBufferAsync(sampleFile, buffer);

感谢您的帮助,希望这能帮助任何人寻找类似的东西

Thanks for helping hope this will help anyone look for something like this

这篇关于从互联网上的txt文件中获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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