在SD卡读写

    		//MEDIA_UNKNOWN:不能识别sd卡
    		//MEDIA_REMOVED:没有sd卡
    		//MEDIA_UNMOUNTED:sd卡存在但是没有挂载
    		//MEDIA_CHECKING:sd卡正在准备
    		//MEDIA_MOUNTED:sd卡已经挂载,可用
    		if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
    		
	    		//返回一个File对象,其路径是sd卡的真实路径 
	    		File file = new File(Environment.getExternalStorageDirectory(), "info.txt");
	//    		File file = new File("sdcard/info.txt");
	    		FileOutputStream fos;
				try {
					fos = new FileOutputStream(file);
					fos.write((name + "##" + pass).getBytes());
					fos.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
    		}
    		else{
    			Toast.makeText(this, "sd卡不可用哟亲么么哒", 0).show();
    		}

你可能感兴趣的:(android)