HOWTO清除而不删除文件中的文本文件? [英] Howto clear a textfile without deleting file?
本文介绍了HOWTO清除而不删除文件中的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问:我有我需要清楚之前,我想补充的信息给它的ini文件
。不幸的是,如果我只是删除该文件,权限都没有了为好。
有没有办法删除一个文件的内容,而删除该文件?
解决方案
字符串PATH =C:/file.ini;
使用(VAR流=新的FileStream(路径,FileMode.Truncate))
{
使用(VAR作家=新的StreamWriter(流))
{
writer.Write(数据);
}
}
Question: I have an ini file which I need to clear before I add info to it.
Unfortunately, if I just delete the file, the permissions are gone as well.
Is there a way to delete a file's content without deleting the file ?
解决方案
String path = "c:/file.ini";
using (var stream = new FileStream(path, FileMode.Truncate))
{
using (var writer = new StreamWriter(stream))
{
writer.Write("data");
}
}
这篇关于HOWTO清除而不删除文件中的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文