当前位置: 编程技术>移动开发
本页文章导读:
▪各种内存储器 各种内存
VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)
PSS - Proportional Set Size 实际使用的物理内存(比例.........
▪ SharePreference的应用 SharePreference的使用
1.定义保存到手机中的xml文件的名字:
private String preferenceName = "Phone_Num";
2.根据key读取出xml中的值。如果读取失败,则默认是" "
SharedPreferences sharedPreferences = getSharedPref.........
▪ 日记接口 日志接口
import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Properties;public class Log8J { private stati.........
[1]各种内存储器
来源: 互联网 发布时间: 2014-02-18
各种内存
- VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
- RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)
- PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)
- USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)
一般来说内存占用大小有如下规律:VSS >= RSS >= PSS >= USS
[2] SharePreference的应用
来源: 互联网 发布时间: 2014-02-18
SharePreference的使用
1.定义保存到手机中的xml文件的名字:
private String preferenceName = "Phone_Num";
2.根据key读取出xml中的值。如果读取失败,则默认是" "
SharedPreferences sharedPreferences = getSharedPreferences(preferenceName, Activity.MODE_PRIVATE); lastPhoneNum = sharedPreferences.getString("phone_num", "");//默认是""
3.保存数据到xml中
SharedPreferences sharedPreferences = getSharedPreferences(preferenceName, Activity.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("phone_num", phoneNum); editor.commit();
[3] 日记接口
来源: 互联网 发布时间: 2014-02-18
日志接口
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
public class Log8J {
private static final Object obj = new Object();
private static final String LOG_NAME_HEAD = "SALog_";
private static final String LOG_NAME_ASSES = ".txt";
private static final String ERROR = "[ERROR]\t";
private static final String INFO = "[INFO]\t";
private static File file = null;
private static FileOutputStream fos = null;
private static Properties prop = new Properties();
private static StackTraceElement[] ste = null;
private StringBuffer sb = new StringBuffer();
static {
try {
prop.load(Log8J.class.getClassLoader().getResourceAsStream("logInfo.properties"));
file = new File(prop.getProperty("logPath") + LOG_NAME_HEAD
+ new SimpleDateFormat("yyyyMMddHH").format(new Date())
+ LOG_NAME_ASSES);
file.createNewFile();
fos = new FileOutputStream(file, true);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void error(String message) {
ste = Thread.currentThread().getStackTrace();
new Log8J().write(ERROR, message, ste);
}
public static void info(String message) {
ste = Thread.currentThread().getStackTrace();
new Log8J().write(INFO, message, ste);
}
private void write(String logType, String message, StackTraceElement[] ste) {
try {
checkFileSize();
String callerInfo = "[" + ste[2].getClassName() + "."
+ ste[2].getMethodName() + "()]\t";
synchronized (obj) {
if (file.length() != 0)
sb.append("\n");
sb.append(makeTimeStamp());
sb.append(logType);
sb.append(callerInfo);
sb.append(message);
}
fos.write(sb.toString().getBytes());
} catch (IOException e) {
System.out.println("The Log function was had a damn ERROR... ...");
e.printStackTrace();
}
}
private static String makeTimeStamp() {
return new SimpleDateFormat("HH:mm:ss").format(new Date()) + "\t";
}
/**
* 检查文件生成的个数,如果超过规定的个数则删除最开始的文件(时间在最前面)
*/
private static void checkFileNum() {
String path = prop.getProperty("logPath");
File file = new File(path);
int factNum = file.list().length;
int targetNum = Integer.valueOf((String) prop.getProperty("logNum"));
int cutNum = 0;
if (factNum > targetNum) {
cutNum = factNum - targetNum;
System.out.println(cutNum);
for (int tmp = 0; tmp < cutNum; tmp++) {
new File(path + file.list()[tmp]).delete();
}
}
}
/***
* 检查文件内容的大小,超过 5242880L 怎重新生成新的文件
*/
private static void checkFileSize() {
if (file.length() < 5242880L)
return;
file = new File(prop.getProperty("logPath") + LOG_NAME_HEAD
+ new SimpleDateFormat("yyMMddHHmm").format(new Date())
+ LOG_NAME_ASSES);
try {
fos = new FileOutputStream(file, true);
} catch (IOException e) {
e.printStackTrace();
}
}
}
logInfo.properties (这里面放置的是一个从log4j.properties自动生成的文件路劲)
logpath = "C\:\\logs\\"
logPath = 15
我的项目是基于struts2和ibatis框架而来的。
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
public class Log8J {
private static final Object obj = new Object();
private static final String LOG_NAME_HEAD = "SALog_";
private static final String LOG_NAME_ASSES = ".txt";
private static final String ERROR = "[ERROR]\t";
private static final String INFO = "[INFO]\t";
private static File file = null;
private static FileOutputStream fos = null;
private static Properties prop = new Properties();
private static StackTraceElement[] ste = null;
private StringBuffer sb = new StringBuffer();
static {
try {
prop.load(Log8J.class.getClassLoader().getResourceAsStream("logInfo.properties"));
file = new File(prop.getProperty("logPath") + LOG_NAME_HEAD
+ new SimpleDateFormat("yyyyMMddHH").format(new Date())
+ LOG_NAME_ASSES);
file.createNewFile();
fos = new FileOutputStream(file, true);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void error(String message) {
ste = Thread.currentThread().getStackTrace();
new Log8J().write(ERROR, message, ste);
}
public static void info(String message) {
ste = Thread.currentThread().getStackTrace();
new Log8J().write(INFO, message, ste);
}
private void write(String logType, String message, StackTraceElement[] ste) {
try {
checkFileSize();
String callerInfo = "[" + ste[2].getClassName() + "."
+ ste[2].getMethodName() + "()]\t";
synchronized (obj) {
if (file.length() != 0)
sb.append("\n");
sb.append(makeTimeStamp());
sb.append(logType);
sb.append(callerInfo);
sb.append(message);
}
fos.write(sb.toString().getBytes());
} catch (IOException e) {
System.out.println("The Log function was had a damn ERROR... ...");
e.printStackTrace();
}
}
private static String makeTimeStamp() {
return new SimpleDateFormat("HH:mm:ss").format(new Date()) + "\t";
}
/**
* 检查文件生成的个数,如果超过规定的个数则删除最开始的文件(时间在最前面)
*/
private static void checkFileNum() {
String path = prop.getProperty("logPath");
File file = new File(path);
int factNum = file.list().length;
int targetNum = Integer.valueOf((String) prop.getProperty("logNum"));
int cutNum = 0;
if (factNum > targetNum) {
cutNum = factNum - targetNum;
System.out.println(cutNum);
for (int tmp = 0; tmp < cutNum; tmp++) {
new File(path + file.list()[tmp]).delete();
}
}
}
/***
* 检查文件内容的大小,超过 5242880L 怎重新生成新的文件
*/
private static void checkFileSize() {
if (file.length() < 5242880L)
return;
file = new File(prop.getProperty("logPath") + LOG_NAME_HEAD
+ new SimpleDateFormat("yyMMddHHmm").format(new Date())
+ LOG_NAME_ASSES);
try {
fos = new FileOutputStream(file, true);
} catch (IOException e) {
e.printStackTrace();
}
}
}
logInfo.properties (这里面放置的是一个从log4j.properties自动生成的文件路劲)
logpath = "C\:\\logs\\"
logPath = 15
我的项目是基于struts2和ibatis框架而来的。
最新技术文章: