try {
File file = new File("/sdcard/test.txt");
FileInputStream inStream = new FileInputStream(file);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024*5];
int length = -1;
while((length = inStream.read(buffer)) != -1 ){
outStream.write(buffer, 0, length);
}
outStream.close();
inStream.close();
String txt= outStream.toString();
} catch (IOException e){
setTitle(e.toString());
}
5.写通讯录
ContentValues values = new ContentValues();
Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
values.put(StructuredName.GIVEN_NAME, name);
getContentResolver().insert(Data.CONTENT_URI, values);
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, num);
values.put(Phone.TYPE, Phone.TYPE_HOME);
getContentResolver().insert(Data.CONTENT_URI, values);
Android手机通讯录备份还原代码下载地址
具体下载目录在 /pub/Android源码集锦/2011年/11月/Android手机通讯录备份还原代码/