将数据保存在C#中的文件 [英] Saving data to a file in C#

查看:151
本文介绍了将数据保存在C#中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我目前工作的一个项目,以便为探索者角色扮演游戏的自动字符表,并很茫然对于如何保存数据。我想我的所有变量的当前值保存到扩展.pfcsheet一个文件并在稍后打开它。我周围的一派,找不到的东西,说如何做到这一点,只是如何保存文本框的内容。我尝试使用saveFileDialog控制,但它一直给我一个文件名是无效错误,并似乎没有人知道为什么。

So i am currently working on a project to make an automated Character Sheet for the Pathfinder Roleplaying Game, and am at a loss as to how to save the data. I want to save the current value of all my variables to a file with the extension .pfcsheet and open it later. I've googled around and can not find something that says how to do this, just how to save the contents of a text box. I tried using the saveFileDialog control but it keeps giving me a "file name is not valid" error and nobody seems to know why.

推荐答案

我想你可能希望这样的事情

I think you might want something like this

// Compose a string that consists of three lines.
string lines = "First line.\r\nSecond line.\r\nThird line.";

// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
file.WriteLine(lines);

file.Close();

这篇关于将数据保存在C#中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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