使用WPF在VB中读取和写入文件 [英] File read and Write in VB with WPF

查看:96
本文介绍了使用WPF在VB中读取和写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我正在制作密码管理器,我想将文件保存为新文件类型(它们是文本文件(使用我自己的加密加密)和新扩展名.dbz)所以我可以创建文件。

使用:_

My.Computer.FileSystem.WriteAllText(String.Concat(location,try.dbz),final,True)



但我有问题是它在写入时不断将新数据添加到原始数据中,我希望它先清除文件中的所有数据然后再写入新数据



我怎么能这样做,或者我可以简单地用代码删除旧文件然后再创建一个新文件

谢谢你

Hello
I was making a password manager , and i want to save files as new file types (they are text files (encrypted with my own encryption) and new extension ".dbz") so i can create file.
using :_
My.Computer.FileSystem.WriteAllText(String.Concat(location, "try.dbz"), final, True)

but i have problem that it keeps adding my new data to original data while writing , i want it to clear all data in file first and then write new data

how can i do that , or can i simply delete old file with code and then create a new file again
thank you

推荐答案

您可以使用 FileStream 并使用< a href =http://msdn.microsoft.com/en-us/library/system.io.filemode.aspx> Truncate 方法,然后向其中写入新数据。
You could use a FileStream and use the Truncate method, then write new data to it.


这篇关于使用WPF在VB中读取和写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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