重命名IsolatedStorage中的文件 [英] Rename File in IsolatedStorage

查看:51
本文介绍了重命名IsolatedStorage中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重命名IsolatedStorage中的文件.我该怎么办?

I need to rename a file in the IsolatedStorage. How can I do that?

推荐答案

在本机C#中似乎没有做到这一点(本机Win32中可能有,但我不知道).

There doesn't appear to anyway in native C# to do it (there might be in native Win32, but I don't know).

您可以做的是打开现有文件,然后将其复制到新文件,然后删除旧文件.与搬家相比,这会很慢,但可能是唯一的方法.

What you could do is open the existing file and copy it to a new file and delete the old one. It would be slow compared to a move, but it might be only way.

var oldName = "file.old"; var newName = "file.new";

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var readStream = new IsolatedStorageFileStream(oldName, FileMode.Open, store))
using (var writeStream = new IsolatedStorageFileStream(newName, FileMode.Create, store))
using (var reader = new StreamReader(readStream))
using (var writer = new StreamWriter(writeStream))
{
  writer.Write(reader.ReadToEnd());
}

这篇关于重命名IsolatedStorage中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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