首页 新闻 会员 周边 捐助

文件“E:\\132.txt”正由另一进程使用,因此该进程无法被访问

0
悬赏园豆:5 [已关闭问题] 关闭于 2013-06-04 13:15

 string l_strOrignSongtxtFullPath = Path.Combine(AddSong_Path, Path.Combine(Common.StaticPath.vod, Common.StaticPath.songtxt));
            string l_strSongTxtBakFullPath = Path.Combine(System.IO.Path.GetDirectoryName(l_strOrignSongtxtFullPath),"songwpbak.txt");
            try
            {
                //判断文件目录是否存在
                if (File.Exists(l_strSongTxtBakFullPath))
                {
                    File.Delete(l_strSongTxtBakFullPath);
                }
                else
                {
                    File.Create(l_strSongTxtBakFullPath, 1000, FileOptions.WriteThrough);
                }

                //获取歌曲单内容          
                byte[] sr = File.ReadAllBytes(l_strOrignSongtxtFullPath);
                FileInfo fi = new FileInfo(l_strOrignSongtxtFullPath);
                long filelen = fi.Length;
                FileStream l_FileStream = new FileStream(l_strSongTxtBakFullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
                //第二次运行会在上面一行出错
                //StreamWriter l_StreamWriter = new StreamWriter(l_strSongTxtBakFullPath, true, Encoding.Default);
                   songcount = filelen / 173;
                   (int i = 0, j = 0; i < filelen; i += 173, j++)
                    {
                        if (sr[171 + i] == 0x0D && sr[172 + i] == 0x0A) //判断内容格式是否正确
                        {
                            string l_strSongPath = AddSong_Path + "\\" + Common.StaticPath.song + Encoding.Default.GetString(sr, j * 173, 2)
                               + "\\" + Encoding.Default.GetString(sr, j * 173 + 2, 2)
                               + "\\" + Encoding.Default.GetString(sr, j * 173 + 4, 2)
                               + "\\" + Encoding.Default.GetString(sr, j * 173, 8);
                            //判断目录下是否存在这个视频文件 如果不存在
                            if (!File.Exists(l_strSongPath + ".mpg") && !File.Exists(l_strSongPath + ".avi") && !File.Exists(l_strSongPath + ".wav"))
                            {
                                //则根据歌单号 删除在歌单资料表的记录
                                string l_MstrSongNo = Encoding.Default.GetString(sr, j * 173, 8).ToString();
                                OleDbConnection MyConnection = new OleDbConnection(Common.CommonObject.constr);
                                MyConnection.Open();
                                string sqlstr = "delete * from 歌单资料 where 编号 ='" + l_MstrSongNo + "'";
                                OleDbCommand comm = new OleDbCommand(sqlstr, MyConnection);
                                comm.ExecuteNonQuery();
                                MyConnection.Close();
                                continue;
                            }
                            l_FileStream.Write(sr, 173 * j, 173);                        }
                    }
                l_FileStream.Close();
                l_FileStream.Dispose();
                File.Delete(l_strOrignSongtxtFullPath);
                File.Copy(l_strSongTxtBakFullPath, l_strOrignSongtxtFullPath, true);
                File.Delete(l_strSongTxtBakFullPath);
                Thread.Sleep(2000);
            }
            catch (IOException ee)
            {
                MessageBox.Show("文件操作异常:"+ee.ToString());
            }

maanshancss的主页 maanshancss | 菜鸟二级 | 园豆:303
提问于:2013-06-04 11:38
< >
分享
所有回答(1)
0

这种一般是没关闭引发的。你试试释放fi。

幻天芒 | 园豆:37207 (高人七级) | 2013-06-04 19:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册