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
文章浏览阅读609次。文章目录一、eNSP是什么?二、安装步骤1.安装VirtualBox2.安装Wireshark3.安装WinPcap4.安装eNSP总结提示:以下是本篇文章正文内容,下面案例可供参考一、eNSP是什么?根据百度百科的解释,eNSP(Enterprise Network Simulation Platform)是一款由华为提供的、可扩展的、图形化操作的网络仿真工具平台,主要对企业网络路由器、交换机进行软件仿真,完美呈现真实设备实景,支持大型网络模拟,让广大用户有机会在没有真实设备的情况下能够模拟演练,_ensp vb
文章浏览阅读2.6k次,点赞2次,收藏3次。新建的OpenGL程序编译时经常会出现[LNK1104 无法打开文件“freeglutd.lib”]问题,如果freeglutd.lib确实放到了正确的路径下,通常可以通过添加“NDEBUG”宏定义解决问题。1 添加NDEBUG如果使用的是Visual Studio,可以使用如下方法添加:在项目属性中选择C/C++ -> 预处理器 -> 预处理器定义 ..._lnk1104 cannot open file 'freeglut.lib
文章浏览阅读5.6k次。 到目前为目,JDBC2的连结池只是一个接口,没有真正的实现,JDBC3正在开发中,据报已经支持连结池,但..........JDBC3用了JNDI技术,连结池的配置可以让一个高手都烦死.目前第三方已经实现的连结池当然是poolman,1.0版对一般用户来说已经足够用了.配置也简单,2.0版虽然增加了一些功能,但配置也是采用JNDI,对RMI和EJB不懂的朋友可能很烦.建议用1.0的了.如果有兴趣_jsp连接池
文章浏览阅读1.4k次。#include <opencv2/highgui/highgui.hpp>#include <opencv2/imgproc/imgproc.hpp>#include <opencv2/opencv.hpp> using namespace cv;using namespace std; #define WINDOW_..._圆环标定板图片生成
文章浏览阅读4.3k次。首先,将项目info选项中的最后一项下拉选中最后一项,然后,在appdelegate中设置- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [UIApplication sharedApplication_iso mac 标题栏色系
文章浏览阅读181次。【给白羊座的1封信】 白羊的人生可以用两个字概括:纠结。不管从哪一方面来说 白羊本身就是一个矛盾的个体。与白羊相恋须知:1.很慢热 我很冷漠 2.很直接 讨厌转弯 3.不喜欢说话 也不喜欢你太吵 4.喜欢自由的感觉 讨厌啰嗦 5.心智很成熟 看事很透彻 6.很绝 7.需要行动证明你爱我。 羊羊人看上去不拘小节 其实感情上道德上有绝对洁癖 触动原则的任何错误哪怕再小都没...
文章浏览阅读2.6k次。MATLAB R2016b 静默安装、激活(Ubuntu 16.04)概要无图形界面环境下,静默安装、激活MATLAB。R2016b的iso安装包分两份,静默安装时需要合并为一份,否则要处理换碟问题。注意:本文的所有命令使用root权限执行。系统环境Ubuntu 16.04文件准备下载安装包(放置在”~/Matlab/”目录下): 1. R2016b_glnxa6..._matlabr2016激活
文章浏览阅读2.5k次,点赞2次,收藏16次。这是一份来自和鲸社区的倒闭企业数据集,总计 6,272 条记录,大小为 2.3 M,包含 21 个字段。_6000条倒闭企业数据分析
文章浏览阅读5.3k次,点赞3次,收藏12次。目录0 前言1 准备工作1.1 引入移动Mas jar包1.2 引入依赖2 完成短信发送功能2.1 编写普通短信发送Service请求Entity响应EntityMd5工具类短信发送Service编写controller,暴露接口3 打包部署4 在项目中调用最近由于业务需求,需要将原先的阿里元短信功能修改成中国移动的Mas。经过几天的研究接口文档,最终实现了:将移动的Mas的普通短信功能打成一个 jar 包,运行在服务器上,实现在业务代码中调用接口中的接口,发送短信的功能。0 前言要使用中国移动的_mas.10086.cn 查看短信发送记录
文章浏览阅读107次。一、什么是冒泡事件事件发生后,浏览器通常首先触发事件发生元素上的事件处理程序,然后是它的父元素,父元素的父元素……依此类推, 直到文档的根元素为止。这被称为事件冒泡,是事件传播的最常见的方式。当处理好一个事件后, 你可能想要停止事件的传播,不希望它继续冒泡。就要绑定该事件的处理方法。如上图,给他们都设置一个点击事件,当点击button时即触发button的点击事件时则会触发相应的父..._什么是jquery的事件冒泡
文章浏览阅读638次。本文实例为大家分享了js调节音量滑块的具体代码,供大家参考,具体内容如下html部分当前位置0%css部分.all {width: 500px;height: 80px;margin: 100px auto;position: relative;}.bar {width: 500px;height: 20px;border-radius: 10px;background: #aaa;positio..._css音量大小
文章浏览阅读785次。推荐几款好用的截图软件_黑马截图软件