Android 保存文件到本地(一)

来源:互联网 发布:步鑫生失败原因 知乎 编辑:程序博客网 时间:2024/05/29 17:21
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;}
0 0
原创粉丝点击