随手记的片段代码
来源:互联网 发布:联系打字速度软件 编辑:程序博客网 时间:2024/05/22 03:35
getDir(“wojiuhsi”,0);//在android中获取目录的一个有效快捷方式 在data/data/包名/files/目录下新建目录wojiushi
try {
//直接会在data/data/com.shiwenjie.myandroid/files/缪录下建立d.txt 文件
FileOutputStream fileOutputStream = openFileOutput(“d.txt”, 0);
fileOutputStream.write(“我就是”.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//文件代表目录 获取该目录下空间
long totalSpace = Environment.getExternalStorageDirectory().getTotalSpace();
String s = Formatter.formatFileSize(context, totalSpace);
System.out.println(s);
long usableSpace = Environment.getExternalStorageDirectory().getUsableSpace(); if (usableSpace<1024*1024*200){ } String use = Formatter.formatFileSize(context, usableSpace); Toast.makeText(context,use,Toast.LENGTH_LONG).show();
随手记工具类
public class SPutils {
private static SharedPreferences userInfo;private static SharedPreferences.Editor edit;{}//存储字符串public static void putString(Context context, String nameKey, String nameValue) { userInfo = context.getSharedPreferences("UserInfo", 0); edit = userInfo.edit(); edit.putString(nameKey, nameValue); edit.commit();}public static String getString( Context context,String nameKey) { userInfo = context.getSharedPreferences("UserInfo", 0); String aNull = userInfo.getString(nameKey, ""); return aNull;}//存储布尔值public static void putBoolean( Context context,String isTrueKey, boolean isTrueValue) { userInfo = context.getSharedPreferences("UserInfo", 0); edit = userInfo.edit(); edit.putBoolean(isTrueKey, isTrueValue); edit.commit();}public static boolean getBoolean(Context context ,String isTrueKey) { userInfo = context.getSharedPreferences("UserInfo", 0); boolean aBoolean = userInfo.getBoolean(isTrueKey, false); return aBoolean;}
}
获取用户信息
private String getUserInfo() {
file = new File(getFilesDir() + File.separator + “userInfo.txt”);
try {
if (!file.exists()) {
file.createNewFile();
}
} catch (IOException e) { e.printStackTrace(); } try { FileInputStream fileInputStream = new FileInputStream(file); BufferedReader buff=new BufferedReader(new InputStreamReader(fileInputStream)); String s = buff.readLine(); System.out.println(s); fileInputStream.close(); usetinfo=s; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return usetinfo;}private void saveUserInfo(String trim, String trim1) { file = new File(getFilesDir() + File.separator + "userInfo.txt"); try { if (!file.exists()) { file.createNewFile(); } } catch (IOException e) { e.printStackTrace(); } try { FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write((trim + "##" + trim1).getBytes()); fileOutputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }}
- 随手记的片段代码
- 随手写的代码记录
- 代码片段的导入
- 实用的代码片段
- 有用的代码片段
- 我的代码片段
- 可用的代码片段
- 有趣的代码片段
- 有用的代码片段
- 有用的代码片段
- 代码片段的备份
- 代码片段的转移
- Adapter的代码片段
- 代码片段: javascript 的slider
- 挂断电话的代码片段
- 有用的Java代码片段
- 有趣的 JavaScript 代码片段
- 常用的.htaccess代码片段
- PBC library 学习笔记(三)
- 微信解除保护模式
- PyCharm 教程(七)管理解释器及第三方模块、包
- 设计模式笔记二十三:策略模式
- 朴素贝叶斯法
- 随手记的片段代码
- MVC模式
- 杭电oj---2004 成绩转换
- 【MySQL】索引结构和建立原则
- poj2299 Ultra-QuickSort 树状数组
- 图论(1)-畅通工程
- Java中如何声明数组
- 前端面试题总结 HTML+CSS篇(一)
- 杭电 2032 杨辉三角