-2

I want to create a local txt file and store username after login success and for next login the app will check on this file if the username exists for bypass login. But it seems like no file created when I testing it

 bool bRet = ws.RequestMemberLogin(1, userName.Text, pass.Text, "", "");

 string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

 string filename = System.IO.Path.Combine(path, "user.txt");

            FileInfo fi = new FileInfo(filename);

            bool exist = fi.Exists;
            if (bRet)
            {
                if (exist)
                {
                    // Read
                    using (StreamReader streamReader = new StreamReader(filename))
                    {
                        string content = streamReader.ReadToEnd();
                        System.Diagnostics.Debug.WriteLine(content);
                    }

                }
                else
                {
                    // Write
                    using (StreamWriter streamWriter = new StreamWriter(filename, true))
                    {
                        streamWriter.WriteLine(userName.Text);
                    }

                }

             Intent intent = new Intent(this, typeof(datalist));
             StartActivity(intent);

            }
            else
            {
                error.Text = "Invalid username or password!";

            }
Chris Lee
  • 7
  • 3

1 Answers1

0

string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

the path will like

"/data/user/0/packagename/files/user.txt"

As you save it to Internal Storage,you couldn't see the files without root permission,if you want to view it,you could use adb tool (application signed by Android Debug)

adb shell
run-as packagename
cd /data/data/packagename
cd files
ls

then you could see the user.txt

or you could save it to External storage,then you could find it in your device File Manager:

//"/storage/emulated/0/Android/data/packagename/files/user.txt"
string path = Android.App.Application.Context.GetExternalFilesDir(null).ToString();
Leo Zhu
  • 15,726
  • 1
  • 7
  • 23