自己項(xiàng)目中的使用的一個庫,整理一下分享給大家
已經(jīng)上傳了github,歡迎大家start
用法
jitpack用起來比較方便
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.evernightking:Storage:v1.0'
}
集成一個application ,在onCreate()方法中去初始化一下
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Store.init(this,"testFile");
}
}
第二個參數(shù)是保存本地的文件名
Store.put("zhangsan", new TestBean());
Store.put("string", "string");
Store.put("int", 100);
Store.put("long", 100L);
Store.put("byte", (byte) 100);
Store.put("short", (short) 100);
Store.put("float", (float) 100);
Store.put("boolean", true);
ArrayList<TestBean> list = new ArrayList<>();
list.add(new TestBean());
list.add(new TestBean());
list.add(new TestBean());
Store.put("listsss", list);
ArrayList<TestBean> listsss = Store.get("listsss", ArrayList.class, null);
TestBean testBean = listsss.get(1);
String s = Store.get("zhangsan", TestBean.class, null).toString() + "\n" +
Store.get("string", "") + "\n"
+ Store.get("int", 0) + "\n" +
Store.get("long", 0L) + "\n" +
Store.get("byte", (byte) 0) + "\n"
+ Store.get("short", (short) 0) + "\n" +
Store.get("float", (float) 0) + "\n" +
Store.get("boolean", true) + "\n"
+ "\n" + testBean.toString();
讀取出來的數(shù)據(jù)展示
文件中保存的數(shù)據(jù)
用base64簡單加密了一下浮毯,使用還是很方便的扎拣,數(shù)據(jù)文件保存在data/data/包名/files/storage/文件夾中
代碼很簡單工秩,就幾個類,感興趣的自己看一下吧