前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Windows Phones 7 文件操作

Windows Phones 7 文件操作

作者头像
蘑菇先生
发布2018-05-21 17:27:08
5730
发布2018-05-21 17:27:08
举报

Windows Phones 文件操作,自己重新测试了一遍,通过,给大家参考使用。

代码语言:javascript
复制
     private const string foldername = "xu";
        private const string filename = "info.txt";
        private const string filepath = foldername +"/"+ filename;
        private const string settingname = "sname";
        /// <summary>
        /// 创建文件夹
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile file=IsolatedStorageFile.GetUserStoreForApplication())
            {
                file.CreateDirectory(foldername);
            }
        }
      //检查文件夹是否存在
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile file=IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (file.DirectoryExists(foldername))
                {
                    MessageBox.Show("存在"+foldername);
                }
                else
                {
                    MessageBox.Show("不存在");
                }
            }
        }
        //删除文件夹
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                file.DeleteDirectory(foldername);
            }
        }

        //创建文件
        private void button6_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
              IsolatedStorageFileStream sd= file.CreateFile(filepath);
        //一定要记得关闭 不然有bug
              sd.Close();
            }
        }
        //判断文件是否存在
        private void button4_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (file.FileExists(filepath))
                {
                    MessageBox.Show("存在"+filepath);
                }
                else
                {
                    MessageBox.Show("不存在");
                }
            }
        }
        //删除文件操作
        private void button5_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                file.DeleteFile(filepath);
            }
        }

        //在文件里增加内容
        private void button7_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile file=IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fs=file.OpenFile(filepath,FileMode.OpenOrCreate,FileAccess.Write))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine("我爱你");
                    } 
                }
            }
        }
        //读取文件内容
        private void button8_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fs = file.OpenFile(filepath, System.IO.FileMode.OpenOrCreate, FileAccess.Read))
                {
                    using (StreamReader sr=new StreamReader(fs))
                    {
                        MessageBox.Show(sr.ReadToEnd());
                    }
                }
            }
        }
        //保存信息配置信息
        private void button9_Click(object sender, RoutedEventArgs e)
        {
            IsolatedStorageSettings.ApplicationSettings[settingname] = "哈哈";
            IsolatedStorageSettings.ApplicationSettings.Save();
            MessageBox.Show("保存成功");
        }
        //读取程序配置信息
        private void button10_Click(object sender, RoutedEventArgs e)
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains(settingname))
            {
                MessageBox.Show(IsolatedStorageSettings.ApplicationSettings[settingname].ToString());
            }
        }
本文参与?腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2012-02-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体同步曝光计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com