(完整版)Android大数据的存储和大数据的访问

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

南昌航空大学实验报告

二0一4 年11 月14 日

课程名称:Android 实验名称:Android数据存储和数据访问

班级:姓名:同组人:

指导教师评定:签名:

一:实验目的

掌握SharedPreferences的使用方法;

掌握各种文件存储的区别与适用情况;

了解SQLite数据库的特点和体系结构;

掌握SQLite数据库的建立和操作方法;

理解ContentProvider的用途和原理;

掌握ContentProvider的创建与使用方法

二:实验工具

Eclipse(MyEclipse)+ ADT + Android2.2 SDK;

三:实验题目

1.应用程序一般允许用户自己定义配置信息,如界面背景颜色、字体大小和字体颜色等,尝试使用SharedPreferences保存用户的自定义配置信息,并在程序启动时自动加载这些自定义的配置信息。

2.尝试把第1题的用户自己定义配置信息,以INI文件的形式保存在内部存储器上。

3.使用代码建库的方式,创建名为test.db的数据库,并建立staff数据表,表内的属性值如下表所示:

4.建立一个ContentProvider,用来共享第3题所建立的数据库;

四:实验代码

InternalFileDemo

public class InternalFileDemo extends Activity {

private final String FILE_NAME = "fileDemo.txt";

private TextView labelView;

private TextView displayView;

private CheckBox appendBox ;

private EditText entryText;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(yout.main);

labelView = (TextView)findViewById(bel);

displayView = (TextView)findViewById(R.id.display);

appendBox = (CheckBox)findViewById(R.id.append);

entryText = (EditText)findViewById(R.id.entry);

Button writeButton = (Button)findViewById(R.id.write);

Button readButton = (Button)findViewById(R.id.read);

writeButton.setOnClickListener(writeButtonListener);

readButton.setOnClickListener(readButtonListener);

entryText.selectAll();

entryText.findFocus();

}

OnClickListener writeButtonListener = new OnClickListener() {

@Override

public void onClick(View v) {

FileOutputStream fos = null;

try {

if (appendBox.isChecked()){

fos = openFileOutput(FILE_NAME,Context.MODE_APPEND);

}

else {

fos =

openFileOutput(FILE_NAME,Context.MODE_PRIVATE);

}

String text = entryText.getText().toString();

fos.write(text.getBytes());

labelView.setText("文件写入成功,写入长度:"+text.length());

entryText.setText("");

} catch (FileNotFoundException e) {

e.printStackTrace();

}

catch (IOException e) {

e.printStackTrace();

}

finally{

if (fos != null){

try {

fos.flush();

fos.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

};

OnClickListener readButtonListener = new OnClickListener() { @Override

public void onClick(View v) {

displayView.setText("");

FileInputStream fis = null;

try {

fis = openFileInput(FILE_NAME);

if (fis.available() == 0){

return;

相关文档
最新文档