我曾經做過一個應用程序,可以選擇將數據導出到設備存儲上的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