我在使用RIM的eclipse插件的Blackberry Playbook上運行我的android應用程序。問題在Android應用程序的BlackBerry Playbook上創建文件?
我在「/ accounts/1000/shared/documents」目錄中創建的文件被「鎖定」(當我瀏覽它們並嘗試使用AIR瀏覽器打開時,出現錯誤消息「file locked」)。我在「/ sdcard」目錄(由Environment.getExternalStorage返回的目錄)中創建的文件正常工作。我可以使用下面的代碼以編程方式創建和讀取這些文件。
有關如何在文檔目錄中創建未鎖定文件的任何建議?
public class TempActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try
{
File docFile = new File("/accounts/1000/shared/documents/tmp.txt");
File sdcardFile = new File(Environment.getExternalStorageDirectory().getPath() + "/tmp.txt");
FileWriter writer = new FileWriter(docFile);
try
{
writer.write("Hello doc file");
Log.i("success writing doc file", "success writing doc file");
}
catch (Exception e)
{
Log.e("exception writing doc file", Log.getStackTraceString(e));
}
writer.close();
writer = new FileWriter(sdcardFile);
try
{
writer.write("Hello sdcard file");
Log.i("success writing sdcard file", "success writing sdcard file");
}
catch (Exception e)
{
Log.e("exception writing sdcard file", Log.getStackTraceString(e));
}
writer.close();
FileReader in = new FileReader(docFile);
BufferedReader reader = new BufferedReader(in);
try
{
Log.i("firstLine in doc file", reader.readLine());
}
catch (Exception e)
{
Log.e("exception reading doc file", Log.getStackTraceString(e));
}
in.close();
reader.close();
in = new FileReader(sdcardFile);
reader = new BufferedReader(in);
try
{
Log.i("firstLine in sdcard file", reader.readLine());
}
catch (Exception e)
{
Log.e("exception reading sdcard file", Log.getStackTraceString(e));
}
in.close();
reader.close();
}
catch (Exception e)
{
Log.e("exception", Log.getStackTraceString(e));
}
}
}
是否有任何理由說明您使用絕對路徑? – 2012-03-20 16:04:17
建議替代? – ab11 2012-03-20 16:07:50
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal – 2012-03-20 16:28:22