我曾经做过一个应用程序,可以选择将数据导出到设备存储上的txt文件。下面是我用的方法:
public void exportTxt(String text){
if(Environment.getExternalStorageState().equalsIgnoreCase("mounted"))//Check if Device Storage is present
{
try {
File root = new File(Environment.getExternalStorageDirectory(), "MyAppFolder");//You might want to change this to the name of your app. (This is a folder that will be created to store all of your txt files)
if (!root.exists()) {
root.mkdirs();
}
File myTxt = new File(root, "filename.txt"); //You might want to change the filename
FileWriter writer = new FileWriter(myTxt);
writer.append(text);//Writing the text
writer.flush();
writer.close();
Toast.makeText(this, "File exported", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "Error: "+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
else
Toast.makeText(this, "Can't access device storage!", Toast.LENGTH_SHORT).show();
}
不要忘了这个权限添加到您的AndroidManifest.xml文件:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
所以为了使用这个方法,所有你需要做的是组将所有currentView数据放在一个字符串中并将其作为参数传递。
谢谢!我还没有尝试过,但看起来我可以从这里管理它......会让你知道它是怎么回事......但无论如何谢谢......暂时,我会考虑这个问题“回答“:) – hanykasem