C#开发Android-文件的读写

            Java.IO.File dirv = new Java.IO.File(filepath);
            if (!dirv.Exists())//工作目录是否存在?
            {
                 dirv.Mkdir();//创建工作目录
            }
            Java.IO.File file = new Java.IO.File(filepath+"/hbdt");
            if (!file.Exists())//工作文件是否存在?
            {
                file.CreateNewFile();//创建工作文件
            }
            //写入方法一
            //writeFileSdcard(file, "aaaaaaaaaaaaa");
            //写入方法二
            FileStream fileOS = new FileStream(filepath + "/hbdt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
            String str="this is a test about Write SD card file";
            Java.IO.BufferedWriter buf1 = new Java.IO.BufferedWriter (new Java.IO.OutputStreamWriter(fileOS));
            buf1.Write(str,0,str.Length);
            buf1.Flush();
            buf1.Close();

            读取
            try
            {
                FileStream fileIS = new FileStream(filepath + "/hbdt",
                    System.IO.FileMode.Open, System.IO.FileAccess.Read);
                Java.IO.BufferedReader buf = new Java.IO.BufferedReader(new Java.IO.InputStreamReader(fileIS));
                string readString;
                 while((readString = buf.ReadLine())!= null)
                 {
                     string s=readString;
                 }
                 fileIS.Close();
            }
            catch (Exception)
            {
                throw;
            }

你可能感兴趣的:(C#.net,Android开发,C#开发android)