if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
//返回一个File对象,其路径是sd卡的真实路径
File f = new File(Environment.getExternalStorageDirectory(),"info.txt");
FileOutputStream fos;
try {
fos = new FileOutputStream(f);
//把『username:pwd』写入info.txt中
fos.write("username:pwd".getBytes());
fos.close();
}catch (Exception e){
e.printStackTrace();
}
}
检测sd卡状态,并往sd卡写入文件
最新推荐文章于 2023-09-08 22:23:10 发布
本文介绍了一个简单的示例,演示如何在Android设备的SD卡上创建并写入一个名为info.txt的文件。该过程包括检查SD卡是否可用,并使用FileOutputStream将字符串username:pwd写入文件。
2286

被折叠的 条评论
为什么被折叠?



