Android写出数据到外部TF卡,可行性方法

来源:互联网 发布:java中this 编辑:程序博客网 时间:2024/06/05 02:10
// 获取内外SD卡的路径,由实际情况而定public String getSDPath() {    File file1 = new File("/storage/sdcard1/");    if (file1.exists()) {        return file1.toString() + "/";    }    return     Environment.getExternalStorageDirectory().toString() + "/";}//创建新的文件public boolean createFile(String path,String filename){    File path = new File(path);    File file = new File(pathName + fileName);    if (!path.exists()) {        Log.d(TAG, "Create the path:" + path);        path.mkdirs(); //创建目录    }    if (!file.exists()) {        Log.d(TAG, "Create the file:" + filename);        try {                file.createNewFile(); //创建文件            } catch (IOException e) {                Log.d(TAG, e.getMessage());            }    }}//调用createFile(getSDPath(),"1.txt");
0 0
原创粉丝点击