public void saveToSdcard(String name,String pwd){
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
File file = new File(Environment.getExternalStorageDirectory(),"yu.txt");
try {
FileOutputStream fosStream = new FileOutputStream(file);
String contextString = name+":"+pwd;
fosStream.write(contextString.getBytes());
fosStream.flush();
fosStream.close();
System.out.println("写入成功");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
System.out.println("请检测内存卡");
}
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
File file = new File(Environment.getExternalStorageDirectory(),"yu.txt");
try {
FileOutputStream fosStream = new FileOutputStream(file);
String contextString = name+":"+pwd;
fosStream.write(contextString.getBytes());
fosStream.flush();
fosStream.close();
System.out.println("写入成功");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
System.out.println("请检测内存卡");
}
}
Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)判断sdcard是否被挂载。
Environment.getExternalStorageDirectory()得到手机sdcrd的跟目录
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long totalbytes = blockSize*totalBlocks;
System.out.println(totalbytes);
这段是得到手机sdcard的大小