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

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

问题描述

我有一个uwp,我需要从保存在互联网上的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天全站免登陆