A:使用自建立应用包下/data/data/包名下的文件保存,不需要权限
1、页面布局截图
2、页面源代码
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:padding="10dp" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="2"
android:gravity="center"
android:text="账户:" />
<EditText
android:id="@+id/account"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="5"
android:hint="请输入账号" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="2"
android:gravity="center"
android:text="密码:" />
<EditText
android:id="@+id/password"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="5"
android:hint="请输入密码"
android:inputType="textPassword" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp" >
<CheckBox
android:id="@+id/cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="是否记住密码" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="5dp" >
<Button
android:id="@+id/exit"
android:layout_width="0dp"
android:layout_weight="1"
android:height="40dp"
android:onClick="click"
android:text="退出" />
<Button
android:id="@+id/login"
android:layout_width="0dp"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:height="40dp"
android:onClick="click"
android:text="登录" />
</TableRow>
</TableLayout>
3、文件保存与读取逻辑实现代码
public class MainActivity extends Activity {
private CheckBox cb;
private EditText et_account;
private EditText et_password;
private File file;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table_login);
cb = (CheckBox) findViewById(R.id.cb);
et_account = (EditText) findViewById(R.id.account);
et_password = (EditText) findViewById(R.id.password);
file = new File(getFilesDir(), "config.txt");
// 读取文件信息
if (file.exists() && file.length() > 0) {
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
String account = line.split("#!qishuichixi!#")[0];
String password = line.split("#!qishuichixi!#")[1];
et_account.setText(account);
et_password.setText(password);
// 组件获得焦点
et_password.setFocusable(true);
et_password.setFocusableInTouchMode(true);
et_password.requestFocus();
et_password.requestFocusFromTouch();
cb.setChecked(true);
} catch (Exception e) {
Toast.makeText(this, "读取文件错误...", Toast.LENGTH_LONG).show();
}
}
}
public void click(View view) {
String account = et_account.getText().toString().trim();
String password = et_password.getText().toString().trim();
switch (view.getId()) {
case R.id.login:
if (TextUtils.isEmpty(account) || TextUtils.isEmpty(password)) {
// 提示语句
Toast.makeText(this, "账号或则密码不能为空...", Toast.LENGTH_LONG).show();
// 重置空白文本
et_account.setText("");
et_password.setText("");
// 组件获得焦点
et_account.setFocusable(true);
et_account.setFocusableInTouchMode(true);
et_account.requestFocus();
et_account.requestFocusFromTouch();
return;
}
if (cb.isChecked()) {
// 第一种 保存文件信息 使用app自带文件夹
// getCacheDir() 缓存文件夹
// 不需要使用权限,即可保存下来
String text = account + "#!qishuichixi!#" + password;
try {
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(text.getBytes("utf-8"));
outputStream.close();
Toast.makeText(this, "保存账号信息成功了...", Toast.LENGTH_LONG)
.show();
} catch (Exception e) {
Toast.makeText(this, "保存账号信息出错了...", Toast.LENGTH_LONG)
.show();
}
}
Toast.makeText(this, "登录成功...", Toast.LENGTH_LONG).show();
break;
case R.id.exit:
finish();
break;
default:
break;
}
}
}
4、文件保存路径
B:使用SD卡存储
1、新建SDActivity
public class SDActivity extends Activity {
private CheckBox cb;
private EditText et_account;
private EditText et_password;
private File file;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table_login);
cb = (CheckBox) findViewById(R.id.cb);
et_account = (EditText) findViewById(R.id.account);
et_password = (EditText) findViewById(R.id.password);
// sd卡没处于挂载状态
if (!Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())) {
Toast.makeText(this, "sd卡错误...", Toast.LENGTH_LONG).show();
return;
}
// sd卡剩余空间大小 字节
long space = Environment.getExternalStorageDirectory().getFreeSpace();
// 转换大小3.98GB
String size = Formatter.formatFileSize(this, space);
System.out.println("sd卡可用空间:" + size);
// 存储路径 三种方式
String path = Environment.getExternalStorageDirectory().getPath();
// String path2="/sdcard/config.txt";
// String path3=Environment.getExternalStorageDirectory().getPath()+"/config.txt";
file = new File(path, "config.txt");
// 读取文件信息
if (file.exists() && file.length() > 0) {
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
String account = line.split("#!qishuichixi!#")[0];
String password = line.split("#!qishuichixi!#")[1];
et_account.setText(account);
et_password.setText(password);
// 组件获得焦点
et_password.setFocusable(true);
et_password.setFocusableInTouchMode(true);
et_password.requestFocus();
et_password.requestFocusFromTouch();
cb.setChecked(true);
} catch (Exception e) {
Toast.makeText(this, "读取文件错误...", Toast.LENGTH_LONG).show();
}
}
}
public void click(View view) {
String account = et_account.getText().toString().trim();
String password = et_password.getText().toString().trim();
switch (view.getId()) {
case R.id.login:
if (TextUtils.isEmpty(account) || TextUtils.isEmpty(password)) {
// 提示语句
Toast.makeText(this, "账号或则密码不能为空...", Toast.LENGTH_LONG).show();
// 重置空白文本
et_account.setText("");
et_password.setText("");
// 组件获得焦点
et_account.setFocusable(true);
et_account.setFocusableInTouchMode(true);
et_account.requestFocus();
et_account.requestFocusFromTouch();
return;
}
if (cb.isChecked()) {
// 第一种 保存文件信息 使用app自带文件夹
// getCacheDir() 缓存文件夹
// 不需要使用权限,即可保存下来
String text = account + "#!qishuichixi!#" + password;
try {
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(text.getBytes("utf-8"));
outputStream.close();
Toast.makeText(this, "保存账号信息成功了...", Toast.LENGTH_LONG)
.show();
} catch (Exception e) {
Toast.makeText(this, "保存账号信息出错了...", Toast.LENGTH_LONG)
.show();
}
}
Toast.makeText(this, "登录成功...", Toast.LENGTH_LONG).show();
break;
case R.id.exit:
finish();
break;
default:
break;
}
}
}
2、需要注意添加SD相关权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- 允许挂载和反挂载文件系统可移动存储 -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
3、设置SDActivity为启动activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
4、存储路径
C:使用shareprefer存储
1、建立SPActivity
public class SPActivity extends Activity {
private CheckBox cb;
private EditText et_account;
private EditText et_password;
private SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table_login);
cb = (CheckBox) findViewById(R.id.cb);
et_account = (EditText) findViewById(R.id.account);
et_password = (EditText) findViewById(R.id.password);
// 读取文件信息
sp = getSharedPreferences("config", Context.MODE_PRIVATE);
String account = sp.getString("account", "");
String password = sp.getString("password", "");
et_account.setText(account);
et_password.setText(password);
if (account != "" && password != "") {
// 组件获得焦点
et_password.setFocusable(true);
et_password.setFocusableInTouchMode(true);
et_password.requestFocus();
et_password.requestFocusFromTouch();
cb.setChecked(true);
}
}
public void click(View view) {
String account = et_account.getText().toString().trim();
String password = et_password.getText().toString().trim();
switch (view.getId()) {
case R.id.login:
if (TextUtils.isEmpty(account) || TextUtils.isEmpty(password)) {
// 提示语句
Toast.makeText(this, "账号或则密码不能为空...", Toast.LENGTH_LONG).show();
// 重置空白文本
et_account.setText("");
et_password.setText("");
// 组件获得焦点
et_account.setFocusable(true);
et_account.setFocusableInTouchMode(true);
et_account.requestFocus();
et_account.requestFocusFromTouch();
return;
}
if (cb.isChecked()) {
try {
// 使用SharedPreferences保存xml数据 Context.MODE_PRIVATE等于0
SharedPreferences sp = getSharedPreferences("config",
Context.MODE_PRIVATE);
sp.edit().putString("account", account)
.putString("password", password).commit();
Toast.makeText(this, "保存账号信息成功了...", Toast.LENGTH_LONG)
.show();
} catch (Exception e) {
Toast.makeText(this, "保存账号信息出错了...", Toast.LENGTH_LONG)
.show();
}
}
Toast.makeText(this, "登录成功...", Toast.LENGTH_LONG).show();
break;
case R.id.exit:
finish();
break;
default:
break;
}
}
}
2、SharedPreferences保存xml文件截图
D:使用sqlite存储
E:源代码下载链接
http://download.csdn.net/detail/qq_30266985/9685053
文章浏览阅读461次。_electron vue项目打开慢
文章浏览阅读229次。接1、2、3、4篇。10、安装mysql支持安装fedora15或者16系统时若选择安装mysql数据库,则必须自行安装mysql开发包。因为自带默认数据库不会安装这个包。否则会遇到mysql错误:ogr_mysql.h:34:23: fatal error: my_global.h: No such file or directory#问题原因:找不到mysql头文件..._linux gdal netcdf5
文章浏览阅读1.2k次。Linux tc qdisc 模拟网络丢包延时_tc qdisc
文章浏览阅读336次。linux64bit 安装 jdk 1.7下载地址 : https://edelivery.oracle.com/otn-pub/java/jdk/7u21-b11/jdk-7u21-linux-x64.rpm0. 卸载rpm版的jdk: #rpm -qa|grep jdk 显示:jdk-1.6.0_10-fcs 卸载:#rpm -e --nodep..._liunx64位得jdk1.7
文章浏览阅读552次。开始听到负载均衡的时候,我第一反应想到的是链路负载均衡,在此之前主要是在学习网络方面知识,像在NA、NP阶段实验做链路负载均衡时常会遇到,后来还接触到SLB负载分担技术,这都是在链路基础上实现的。 其实负载均衡可以分为硬件实现负载均衡和软件实现负载均衡。 硬件实现负载均衡:常见F5和Array负载均衡器,配套专业维护服务,但是成本昂贵。 软件实现负载均衡:常见开源免费的负载均衡软件有Ngin..._中间件应用场景nginx lvs proxy
文章浏览阅读4.7k次。多维时序 | MATLAB实现CNN-LSTM多变量时序预测目录多维时序 | MATLAB实现CNN-LSTM多变量多步预测基本介绍模型特点程序设计学习总结参考资料基本介绍本次运行测试环境MATLAB2020b,MATLAB实现CNN-LSTM多变量多步预测。模型特点深度学习使用分布式的分层特征表示方法自动提取数据中的从最低层到最高层固有的抽象特征和隐藏不变结构. 为了充分利用单个模型的优点并提高预测性能, 现已提出了许多组合模型。CNN 是多层前馈神经网络, 已被证明在提取隐藏_cnn可以进行多步预测
文章浏览阅读219次。3.1 用户配置文件和密码配置文件3.2 用户组管理3.3 用户管理3.4 usermod命令3.5 用户密码管理3.6 mkpasswd命令_polkitd:input 用户和组
文章浏览阅读670次。主成分分析,即Principal Component Analysis(PCA),是多元统计中的重要内容,也广泛应用于机器学习和其它领域。它的主要作用是对高维数据进行降维。PCA把原先的n个特征用数目更少的k个特征取代,新特征是旧特征的线性组合,这些线性组合最大化样本方差,尽量使新的k个特征互不相关。关于PCA的更多介绍,请参考:https://en.wikipedia.org/wiki/Prin..._inprementation python code of pca
文章浏览阅读35次。发一下牢骚和主题无关:地址类型:32位的cpu,共4G间空,其中0-3G属于用户间空地址,3G-4G是内核间空地址。用户虚拟地址:用户间空程序的地址物理地址:cpu与内存之间的用使地址总线地址:外围总线和内存之间的用使地址内核逻辑地址:内存的分部或全体射映,大多数情况下,它与物理地址仅差一个偏移量。如Kmalloc分..._linux 内存条与内存地址
文章浏览阅读1.3k次,点赞2次,收藏16次。什么是自动化测试? 做测试好几年了,真正学习和实践自动化测试一年,自我感觉这一个年中收获许多。一直想动笔写一篇文章分享自动化测试实践中的一些经验。终于决定花点时间来做这件事儿。 首先理清自动化测试的概念,广义上来讲,自动化包括一切通过工具(程序)的方式来代替或辅助手工测试的行为都可以看做自动化,包括性能测试工具(loadrunner、jmeter),或自己所写的一段程序,用于_自动化测试中baw库指的什么
文章浏览阅读1.6w次。A0纸指的是一平方米大小的白银比例长方形纸(长为1189mm宽为841mm)。A0=1189mm*841mm A1=841mm*594mm 相当于1/2张A0纸 A2=594mm*420mm 相当于1/4.A1图纸大小尺寸:841mm*594mm 即长为841mm,宽为594mm 过去是以多少"开"(例如8开或16开等)来表示纸张的大小,我国采用国际标准,规定以 A0、A1、A2、.GB/T 14..._a0图纸尺寸
文章浏览阅读966次。最终效果图:UI说明:针对table本身进行增强的tree table组件。 tree的数据来源是单元格内a元素的自定义属性:level和type。具体代码如下:Java代码 DepartmentEmployeeIDposi_treetable canvas