HOWTO清除而不删除文件中的文本文件?而不、文本文件、文件、HOWTO

2023-09-04 22:39:58 作者:帅逼者`~

问:我有我需要清楚之前,我想补充的信息给它的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");
        }
    }

 
精彩推荐
图片推荐