首先先讲一下如何在Sd卡上创建文件
File dir=new File(Environment.getExternalStorageDirectory(),"photo"); if (!dir.exists()) { dir.mkdirs(); } File f=new File(dir,System.getCurrentTime()+".jpg"); if (!f.exists()) { f.createNewFile();//本句需要try块包裹 }
读取Sd卡内容
File f = new File(path); FileInputStream fis = new FileInputStream(f); int length = (int) f.length(); byte[] b = new byte[length]; fis.read(b,0,length); String data=""; for(byte elements:b){ data+=elements; } fis.close();
向Sd卡写入
File file=new File(path); FileOutputStream fos=new FileOutputStream(file); fos.write(data); fos.flush(); fos.close();