我正在使用RIM的eclipse插件在Blackberry Playbook上运行我的Android应用程序。
我在“/ accounts / 1000 / shared / documents”目录中创建的文件被“锁定”(当我浏览它们并尝试使用AIR浏览器打开时,我收到错误消息“文件已锁定”)。我在“/ 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));
}
}
}
答案 0 :(得分:1)