9
嗨我需要創建和寫入文本文件到/ data目錄中。創建和寫入Android設備/數據文件夾的文件
這是我正在使用的代碼。
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("chmod 777 /data");
process.waitFor();
resultFile = new File(Environment.getDataDirectory()
+ "/resultfile.txt");
Log.i(TAG,"File Object Created....."+resultFile);
} catch (Exception e) {
Log.i(TAG, "Exception in Environment.getDataDirectory()"
+ e.toString());
}
try {
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("chmod 777 /data/resultfile.txt");
process.waitFor();
if (!resultFile.exists())
resultFile.createNewFile();
} catch (IOException ioException) {
Log.i(TAG, "Exception in creating file..."
+ ioException.toString());
}
try {
if (fileWriter == null)
fileWriter = new FileWriter(resultFile);
} catch (FileNotFoundException fileNotFoundException) {
Log.i(TAG, "FileNotFoundException....."
+ fileNotFoundException.toString());
}
,但我得到下面這些問題......
Exception in creating file...java.io.IOException: Permission denied
FileNotFoundException.....java.io.FileNotFoundException: /data/resultfile.txt (Permission denied)
Exception in saveResultsToFile.....java.lang.NullPointerException
PLZ幫我在這...謝謝。
然後,我不想將其存儲在共享首選項或外部存儲器中的替代方法是什麼... – brig 2011-05-19 07:19:08
您沒有任何其他選項。您可以將應用程序保存在應用程序的專用區域或外部存儲器中。 – 2011-05-19 07:21:41
什麼意思是應用程序的私人領域,可以詳細說明這個.. ?? – brig 2011-05-19 07:28:31