C#播放声音的两个方法 + 流读写文件

第一种方法:

                 利用API播放声音文件

using System.Runtime.InteropServices; 在调用API时先引用

     

[DllImport("winmm")]
public static extern bool PlaySound(string szSound, IntPtr hMod, int i);   //声明API:PlaySound

调用:

PlaySound(@"声音文件路径",IntPtr.Zero,1);

第二种方法:

                 利用windows media player播放声音

System.Media.SoundPlayer media = new System.Media.SoundPlayer(@"声音文件路径");
mdeia.Play();

流写文件

            System.IO.StreamWriter strwri = File.CreateText(@"d:\111.log");
            strwri.WriteLine("abc");
            strwri.WriteLine("def");
            strwri.Flush();
            strwri.Dispose();

流读文件

            StreamReader dd = new StreamReader(@"d:\11.txt");
           MessageBox.Show(dd.ReadLine());


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wenjie0728/archive/2009/04/14/4073690.aspx

posted @ 2010-03-02 15:09  钢的锅  阅读(3725)  评论(1编辑  收藏  举报