private void createFile() {    File sdCard= Environment.getExternalStorageDirectory();    String fileName = "data.txt";    File file = new File(sdCard, fileName) ;    if(!file.exists()){        try {            file.createNewFile();            String oldPath = file.getAbsolutePath();            String newPath =  "";            newPath = oldPath.replace(fileName, "other.txt");            renameFile(oldPath, newPath);            //file is create        } catch (IOException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    } else {        String oldPath = file.getAbsolutePath();        if(!TextUtils.isEmpty(oldPath)) {            String newPath = file.getAbsolutePath() + "other.txt";            newPath = oldPath.replace(fileName, "other.txt");            renameFile(oldPath, newPath);        }    }}/** * oldPath newPath必须是新旧文件的绝对路径 * */private void renameFile(String oldPath, String newPath) {    if(TextUtils.isEmpty(oldPath)) {        return;    }    if(TextUtils.isEmpty(newPath)) {        return;    }    File file = new File(oldPath);    file.renameTo(new File(newPath));}

更多相关文章

  1. android根据uri或文件绝对路径获取文件基本信息
  2. Android 根据Video绝对路径获取其缩略图
  3. android 安卓 开发 图片库获得图片的绝对路径
  4. PHP获取绝对路径dirname(__FILE__)和__DIR__比较
  5. XHTML 相对路径与绝对路径
  6. 如何在Linux中以编程方式获取给定相对路径的绝对路径?
  7. 确定shell程序中的相对路径或绝对路径

随机推荐

  1. 范例解析:学习Android的IPC主板模式
  2. Android(安卓)2.3系统令人为之兴奋的十大
  3. 【Android(安卓)内存优化】Bitmap 内存缓
  4. 波音787 Dreamliner娱乐系统将选择Androi
  5. android 字节数据的转换与处理
  6. 是时候让 Android(安卓)Tools 属性拯救你
  7. pc 应用 通过 usb adb 与 android客户端
  8. ArcGIS for Android(安卓)Runtime100 基
  9. 使用jni接口完成android本地程序的运行--
  10. flutter系列之flutter工程如何与android