读写sd卡文件,只需要用普通Java io就可以了,Environment.getExternalStorageDirectory()为sd卡路径的File
注意:用模拟器运行时需要加载sd卡支持,否则会报read-only system
一,写文件
try {
File myfile = new File(Environment.getExternalStorageDirectory(), "MyDemo.txt");
OutputStream os = new FileOutputStream(myfile);
os.write("hello".getBytes());
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
二,读文件
try{
File myfile = new File(Environment.getExternalStorageDirectory(), "MyDemo.txt");
InputStream file = new FileInputStream(myfile);
byte[] b = new byte[(int)myfile.length()];
file.read(b);
Log.d(TAG, new String(b));
}catch(Exception e){
e.printStackTrace();
}