读取和写入文件到可移动SD卡 [英] read and write files to removable sd card
本文介绍了读取和写入文件到可移动SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何阅读和Android的文件写入到可移动SD卡?
我要存储的Android标识的文本文件。该文本文件应在外部SD卡创建的。
code:
PackageManager M = getPackageManager();
字符串s = getPackageName();
PackageInfo p值= m.getPackageInfo(S,0);
S = p.applicationInfo.dataDir;
myfile文件=新的文件(S +/MyDoople.txt);
myFile.createNewFile();
FileOutputStream中FOUT =新的FileOutputStream(MYFILE);
OutputStreamWriter myOutWriter =新OutputStreamWriter(FOUT);
myOutWriter.append(TxtS.getText());
myOutWriter.close();
fOut.close();
Toast.makeText(getBaseContext(),文本更新,Toast.LENGTH_SHORT).show();
二是
文件SD卡=新的文件(文件:/// MNT / external_sd /);
myfile文件=新的文件(SD卡的test.txt);
FileWriter的作家=新的FileWriter(MYFILE);
writer.append(的TestString);
writer.flush();
writer.close();
解决方案
我的问题就解决了。 我直接使用路径到/ mnt / external_sd / ..文件的路径。
但它只是与我的设备工作
How to read and write files to removable sd card in Android?
I want to store Android Id in Text file. The text file should be created on external sdcard.
Code:
PackageManager m = getPackageManager();
String s = getPackageName();
PackageInfo p = m.getPackageInfo(s, 0);
s = p.applicationInfo.dataDir;
File myFile = new File(s + "/MyDoople.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append(TxtS.getText());
myOutWriter.close();
fOut.close();
Toast.makeText(getBaseContext(),"Text Updated",Toast.LENGTH_SHORT).show();
The Second is
File sdCard = new File("file:///mnt/external_sd/");
File myFile = new File(sdCard, "test.txt");
FileWriter writer = new FileWriter(myFile);
writer.append(TESTSTRING);
writer.flush();
writer.close();
解决方案
My question is solved. I directly use the path "/mnt/external_sd/.. Path of File.".
But it was only work with my Device
这篇关于读取和写入文件到可移动SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文