androidSD卡的一些相关操作

来源:互联网 发布:windows ant工具 编辑:程序博客网 时间:2024/04/29 02:30
                 //判断SDcard是否可用           if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){        //Environment.getExternalStorageDirectory(); 返回的是/mnt/sdcard        File file = new File(Environment.getExternalStorageDirectory(),"hello.txt");        Toast.makeText(this, file.toString(), 3000).show();        try {final FileOutputStream out = new FileOutputStream(file);try {out.write("写SDCARD的操作".getBytes());} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{if(out!=null){try {out.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}        }

上面的代码主要是用来判断SDcard卡是否可用,并且在SDcard上面创建相应的文件。

因为是操作SDcard所以要导入想SDscard的相关权限.

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

原创粉丝点击