zoukankan      html  css  js  c++  java
  • [Windows Phone 7璀璨]北漂1.0在线歌词播放器四.独立储存空间歌词的读取(完结)

    一.独立储存空间歌词的读取

    1.1保存歌词文件

    View Code
     1 /// <summary>
    2 /// 保存歌词文件
    3 /// </summary>
    4 /// <param name="SongName">歌曲名</param>
    5 /// <param name="Artist">艺术家</param>
    6 /// <param name="lyrics">歌词文件</param>
    7 public void Save(string SongName, string Artist, string lyrics)
    8 {
    9 IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
    10 //如果文件夹不存在
    11 if (!(file.DirectoryExists("Lrc") ? true : false))
    12 {
    13 file.CreateDirectory("Lrc");
    14
    15 }
    16 StringBuilder sb=new StringBuilder();
    17 sb.Append("Lrc//");
    18 sb.Append(SongName);
    19 sb.Append(Artist);
    20 sb.Append(".txt");
    21 StreamWriter fileWrite=new StreamWriter(new IsolatedStorageFileStream(sb.ToString(),FileMode.Create,file));
    22 fileWrite.WriteLine(lyrics);
    23 fileWrite.Close();
    24
    25
    26
    27 }


    1.2 读取文件

    View Code
     1 /// <summary>
    2 /// 读取文件
    3 /// </summary>
    4 /// <param name="SongName"></param>
    5 /// <param name="Artist"></param>
    6 /// <returns></returns>
    7 public string Read(string SongName, string Artist)
    8 {
    9 StringBuilder sb=new StringBuilder();
    10 sb.Append("Lrc//");
    11 sb.Append(SongName);
    12 sb.Append(Artist);
    13 sb.Append(".txt");
    14 string lrc="文件不存在";
    15 IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
    16 if(file.FileExists(sb.ToString())?true:false)
    17 {
    18 StreamReader sr=new StreamReader(new IsolatedStorageFileStream(sb.ToString(),FileMode.Open,file));
    19 lrc=sr.ReadToEnd();
    20 sr.Close();
    21
    22 }
    23 return lrc;
    24 }

    1.3判断歌词是否存在

    View Code
     1  /// <summary>
    2 /// 判断歌词是否存在
    3 /// </summary>
    4 /// <param name="SongName"></param>
    5 /// <param name="Artist"></param>
    6 /// <returns></returns>
    7 public bool decide(string SongName, string Artist)
    8 {
    9 IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
    10 StringBuilder sb = new StringBuilder();
    11 sb.Append("Lrc//");
    12 sb.Append(SongName);
    13 sb.Append(Artist);
    14 sb.Append(".txt");
    15 return file.FileExists(sb.ToString()) ? true : false;
    16 }

    完整源代码:

    http://dl.dbank.com/c0st7kbm1n


  • 相关阅读:
    130行C语言实现个用户态线程库(2)
    130行C语言实现个用户态线程库(1)
    用C语言模仿Python函数
    ES 2.4 bigdesk 安装失败解决方案.
    使用SqlBulkCopy, 插入整个DataTable中的所有数据到指定数据库中
    表A的数据减去表B ,最终得到表C
    关于把A表中的数据复制到B表中(整理)
    需求池整理
    app主流推广渠道
    流程图梳理
  • 原文地址:https://www.cnblogs.com/tubufeng/p/2404815.html
Copyright © 2011-2022 走看看