C#PCL阅读从文件 [英] C# PCL Reading from File

查看:707
本文介绍了C#PCL阅读从文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在写一个便携式类库,面向.NET 4.5,Windows 8和Windows Phone的8我想从一个文本文件,该项目为建设内容的​​一部分阅读。我看到的StreamReader在PCL的使用,但我似乎无法找出如何从一个文件中获取流,给定一个文件路径。如果任何人都可以点我的权利结构我将不胜感激。此外,如果你能给方向的XML文件,太。我只读取文本文件的权利,但我会在以后的XML工作。谢谢!

So I'm writing a portable class library that targets .NET 4.5, Windows 8 and Windows Phone 8. I'm trying to read from a text file that is part of the project as build content. I see that StreamReader is available in PCL's but I can't seem to find out how to get the stream from a file, given a file path. If anyone could point me to the right structures I'd appreciate it. Also if you could give direction for XML files, too. I'm only reading text files right now, but I'm going to be working in XML later. Thanks!

推荐答案

便携式类库允许您使用中存在的所有你所定位的平台命名空间和类工作。结果
.NET 4.5(假设你的意思是完整的桌面的WinForms / WPF),Windows 8和Windows Phone的8都做文件访问非常不同,并有向他们提供不同的文件。凡文件可以同时访问有很大的不同:嵌入的内容;嵌入的资源;独立存储;共享文件夹;完整的文件系统。这些不都是适用于所有你提到的平台。

Portable class libraries allow you to work with namespaces and classes that exist in all the platforms that you're targeting.
.Net 4.5 (assuming you mean the full desktop-WinForms/WPF), Windows 8 and Windows Phone 8 all do file access very differently and have different files available to them. Where files can be accessed from also differs greatly: embedded content; embedded resources; isolated storage; shared folders; the full file system. These aren't all available on all the platforms you mention.

简短的回答。你可能不能做你以后。

Short answer. You probably can't do what you're after.

文件系统访问跨平台的变化很大,通常都必须为每个平台做不同。结果
你可以做的是定义文件的接口访问(打开,读取,保存,等等),你的PCL可以使用,然后创建平台特定实例传递给需要的PCL。

File system access varies dramatically across platforms and typically has to be done differently for each platform.
What you can do is define an interface for file access (open, read, save, etc.) that your PCL can use and then create platform specific instances that you pass to the PCL as needed.

这篇关于C#PCL阅读从文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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