使用文件
我需要创建一个读取文件的应用程序,如下所示:
Font = "Courier New"
Size = "10"
Style = "Bold"
如您所见,我将使用它来设置 TextBox 的一些属性,但我将存储每个内容在这些引号内并将它们存储在一些变量中(textFont
、textSize
、textStyle
)。
我认为我可以使用这种语法来打开带有文件的流:
StreamReader reader = new StreamReader("confs.txt");
问题是:
- 当声明 StreamReader 时,它将读取应用程序目录中的文件?(只是为了确认)
- 我怎样才能只读取引号内的内容并将每个存储在一个字符串中?
我认为,文件 I/O 在 Windows Mobile 和 Windows 中是相同的。此致
I'm needing to create a application that will read a file, that will be like this:
Font = "Courier New"
Size = "10"
Style = "Bold"
As you can see I'm going to use this to set some properties of a TextBox, but I'm going to store each thing that is inside these quotes and store they on some variables(textFont
, textSize
, textStyle
).
I think that I can use this syntax to open a stream with the file:
StreamReader reader = new StreamReader("confs.txt");
The questions are:
- As the StreamReader is declared it will read the file in the application directory?(Just to Confirm)
- How can I read only what is inside the quotes and store each one in a string?
As I think, file I/O is iqual in Windows Mobile and Windows. Best Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
像这样的事情怎么样:
您创建的是一个简单的 CSV 文件
,其中 CSV 我的意思是字符分隔值...
更新
好的,看起来您正在尝试精确复制而不是理解算法,所以我将在这里创建一个新的
How about something like this:
What you have created is a simple CSV file
Where by CSV I mean Character Separated Value...
Update
Ok, seems like you are trying to copy exactly instead of understanding the algorithm so I will create a new one here
最好声明完整路径,或使用以下语法:
我认为解析它,您可以更轻松地将文件保存为 Xml 并将其加载到 XmlDocument 中。或者更好的是,放弃这个想法并将这些信息存储在 app.config 文件中。它非常容易,如果需要的话,您仍然可以在记事本中编辑它,而无需重新编译。
(这会使答案的前半部分变得毫无意义)
It's better to declare the full path, or use the following syntax:
I think to parse it, you would have an easier time saving the file as Xml and loading it into an XmlDocument. Or better yet, abandon this idea and store tine information in the app.config file. It's so much easier and you still get to edit it in notepad without recompiling if you need to.
(which would render the first half of the answer as moot)
1:只要不改变当前目录就可以。还有更彻底的方法来获取应用程序目录,不过
有两种:解析此类字符串的任意多种方法;
string.Split
、Regex
等;纯粹作为说明,我将(ab)使用DbConnectionStringBuilder
:编辑
DbConnectionStringBuilder
可能不存在于windows-mobile中;也许只是=
上的Split
或使用Regex
;它归结为精确格式。1: as long as you don't change the current directory, yes. There are more thorough ways to get the app directory, though
2: any number ways to parse such a string;
string.Split
,Regex
, etc; purely as an illustration, I'll (ab)useDbConnectionStringBuilder
:edit
DbConnectionStringBuilder
may not exist in windows-mobile; perhaps justSplit
on=
or useRegex
; it comes down to the exact format.