登陆界面的数据保存回显的操作 (三)

2014-11-24 10:55:34 · 作者: · 浏览: 15
;

}

// 读取数据
public Map readFile(String fileName) {
Map map = null;// new HashMap();

try {
FileInputStream fis = context.openFileInput(fileName);
String value = StreamTools.getValue(fis);
String values[] = value.split(":");

if (values.length > 0) {
map = new HashMap();
map.put("name", values[0]);
map.put("pass", values[1]);
}

} catch (Exception e) {
e.printStackTrace();
}
return map;
}

}
package com.example.lession02_file.util; 

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;

public class StreamTools {

public static String getValue(FileInputStream fis) throws Exception {
//字节的输出流对象
ByteArrayOutputStream stream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length = -1;
while ((length = fis.read(buffer)) != -1) {
stream.write(buffer, 0, length);
}
stream.flush();
stream.close();

String value = stream.toString();

return value;
}
}


     xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >



android:layout_width="match_parent"
android:layout_height="wrap_content" >

android:id="@+id/View_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/file_name" />

android:id="@+id/edit_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" >






android:layout_width="match_parent"
android:layout_height="wrap_content" >

android:id="@+id/View_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/file_pass" />

android:id="@+id/edit_pass"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPassword" />



android:layout_width="match_parent"
android:layout_height="wrap_content" >