如何在登录成功时将用户名写入本地txt文件并检查文件以备下次登录? [英] How to write the username in a local txt file when login success and check on file for next login?
问题描述
我想在登录成功后创建一个本地 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屋!