e.printStackTrace到底在哪能看到的?

中才德创 2014-05-05 11:09:36
public class logManager {
private static final String TAG = "logManager";
private static final int LOG_FILE_MAX_SIZE = 1 * 1024;

public static File getLogFile() {
String dir = android.os.Environment.getExternalStorageDirectory() + "/Log/";
String filepath = null;

try {
File file = new File(dir);
long size = 0;
if (!file.exists()) {
file.mkdir();
}

filepath = dir + "log01.txt";
file = new File(filepath);
if (!file.exists()) {
file.createNewFile();
return file;
}
else {
size = file.length();
if(size >= LOG_FILE_MAX_SIZE) {
filepath = dir + "log02.txt";
file = new File(filepath);
if (!file.exists()) {
file.createNewFile();
return file;
}
else {
size = file.length();
if(size >= LOG_FILE_MAX_SIZE) {
filepath = dir + "log01.txt";
file = new File(filepath);
if(file.exists()) {
file.delete();
}
file.createNewFile();
return file;
}
else {
return file;
}
}
}
else {
return file;
}
}

} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return null;
}
}

public static void saveLogSD(String log) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
format.setTimeZone(TimeZone.getDefault());
String time = format.format(new Date(System.currentTimeMillis()));
File file = getLogFile();
String content = time + " " + log;

FileOutputStream fileOutput = null;

try {
fileOutput = new FileOutputStream(file, true);
fileOutput.write(content.getBytes());
fileOutput.flush();

fileOutput.close();
fileOutput = null;

return;
} catch (FileNotFoundException e) {
Log.d(TAG, "saveLogSD() error:" + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Log.d(TAG, "saveLogSD() error:" + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != fileOutput) {
fileOutput.close();
fileOutput = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
...全文
1476 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
中才德创 2014-05-05
  • 打赏
  • 举报
回复
我的意思是:e.printStackTrace这种方法与Log.d明显不同,是不是显示的地方会更广一些。比如,发布了,在运行期手机界面上,将出错信息以某种形式显示出来。
  • 打赏
  • 举报
回复
在debug的模式下可以看到啊,或者你 e.printStackTrace(); System.out.println("aaaaaaaaaaaaaaaaa"+e.getMessage());总能在log里面看到了
Johnny-xz 2014-05-05
  • 打赏
  • 举报
回复
异常信息在Logcat里面才可以看到
映映 2014-05-05
  • 打赏
  • 举报
回复
logcat中看到
网络咖啡 2014-05-05
  • 打赏
  • 举报
回复
异常信息只有在Logcat里面才可以看到,真机上是看不到的,但是发布程序以前最好把这样的代码注释掉,影响性能。

80,471

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧