登录成功后,如何在本地txt文件中写入用户名并检查文件以进行下次登录? [英] How to write the username in a local txt file when login success and check on file for next login?

查看:43
本文介绍了登录成功后,如何在本地txt文件中写入用户名并检查文件以进行下次登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个本地txt文件,并在登录成功后存储用户名,对于下一次登录,应用程序将检查该文件(如果存在用于旁路登录的用户名).但是当我测试它时似乎没有创建文件

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!";

            }

推荐答案

字符串路径= System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

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

路径会喜欢

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

当您将其保存到内部存储,没有root权限就看不到文件,如果要查看它,可以使用 adb 工具(由Android Debug签名的应用程序)

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

然后您会看到 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();

这篇关于登录成功后,如何在本地txt文件中写入用户名并检查文件以进行下次登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆