您的位置:首页 > 移动开发 > Android开发

Android 保存文件到本地(一)

2015-12-17 11:09 369 查看
public boolean method1(String conent) {

String path = "./mnt/sdcard/ucabCrash/";
String fileName = "myloction.txt";

File dirFile = new File(path);
File file = new File(path + fileName);

if (!dirFile.exists()) {
dirFile.mkdirs();
try {
file.createNewFile();
} catch (Exception e) {
Log.e("calm", "------创建异常---");
return false;
}
}

SimpleDateFormat sdf = new SimpleDateFormat("yyyy MM dd HH:mm:ss", Locale.getDefault());
long timestamp = System.currentTimeMillis();
String time = sdf.format(new Date(timestamp));
conent = time + conent + '\n';
BufferedWriter out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(path + fileName, true)));
out.write(conent);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}

return true;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: