android,SD卡的文件读取问题
fileName=(EditText)findViewById(R.id.filename);fileContent=(EditText)findViewById(R.i...
fileName = (EditText)findViewById(R.id.filename);
fileContent = (EditText)findViewById(R.id.filecontent);
String filename = fileName.getText().toString();
String filecontent = fileContent.getText().toString();
File path = Environment.getExternalStorageDirectory();// 获得SD卡路径
// File path = new File("/mnt/sdcard/");
FileService service = new FileService(getApplicationContext());
try {
//判断SDcard是否存在并且可读写
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
service.saveToSDCard(filename,filecontent);
Toast.makeText(getApplicationContext(), R.string.success, 1).show();
}else{
Toast.makeText(getApplicationContext(), R.string.error, 1).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), R.string.error, 1).show();
e.printStackTrace();
}
看了一些资料说SD卡的读写例如上面代码这样。我写完后下到手机,后发现被保存的文件存到了手机内置的存储空间(三星gt-s7272,内存2G),并没有存到我另外插的8G的卡上。用程序怎么保存到这张8G的?一句话:怎么读取外插的卡。。现在貌似就存到了手机上了,有没有什么类似Environment.getExternalStorageDirectory() 的API访问外插卡。。求大神指导。 展开
fileContent = (EditText)findViewById(R.id.filecontent);
String filename = fileName.getText().toString();
String filecontent = fileContent.getText().toString();
File path = Environment.getExternalStorageDirectory();// 获得SD卡路径
// File path = new File("/mnt/sdcard/");
FileService service = new FileService(getApplicationContext());
try {
//判断SDcard是否存在并且可读写
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
service.saveToSDCard(filename,filecontent);
Toast.makeText(getApplicationContext(), R.string.success, 1).show();
}else{
Toast.makeText(getApplicationContext(), R.string.error, 1).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), R.string.error, 1).show();
e.printStackTrace();
}
看了一些资料说SD卡的读写例如上面代码这样。我写完后下到手机,后发现被保存的文件存到了手机内置的存储空间(三星gt-s7272,内存2G),并没有存到我另外插的8G的卡上。用程序怎么保存到这张8G的?一句话:怎么读取外插的卡。。现在貌似就存到了手机上了,有没有什么类似Environment.getExternalStorageDirectory() 的API访问外插卡。。求大神指导。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询