if (myFile.Exists == false)
            {
                myFile.Create().Close();
            }

解决方案 »

  1.   

    我也碰到过类似的情况,不要用fileinfo.create 来创建文件.改用文件流
    FileInfo myFile = new FileInfo(Application.StartupPath + "/logintext.txt");
                if (myFile.Exists == false)
                {
                    using (FileStream fs = myFile.Create())
                    {
                       Byte[] info =    new UTF8Encoding(true).GetBytes("This is some text in the file.");                   
                        fs.Write(info, 0, info.Length);
                    }            }
            
                StreamReader sr = null;
                sr = new StreamReader(Application.StartupPath + "/logintext.txt", System.Text.Encoding.UTF8);
                string mystr = sr.ReadLine();
                textBox1.Text = mystr;
                sr.Close();
      

  2.   

    FileInfo myFile = new FileInfo(Application.StartupPath + "/logintext.txt");
    if (!myFile.Exists)
    {
    FileStream fs = File.Create(myFile.FullName);
    fs.Close();
    }
      

  3.   

    if(!System.IO.File.Exists(Application.StartupPath+@"\logintext.txt"))
    {
        System.IO.File.Create(Application.StartupPath+@"\logintext.txt");}
      

  4.   

    问题解决
                FileInfo myFile = new FileInfo(Application.StartupPath + @"\logintext.txt");
                FileStream fs = null;
                if (myFile.Exists == false)
                {
                    fs = myFile.Create();
                }
                else
                {
                    fs = myFile.Open(FileMode.Open);
                }
                            StreamReader sr = null;
                sr = new StreamReader(fs);
                string mystr = sr.ReadLine();
                loginuser.Text = mystr;
                sr.Close()