只是想我會更新至少部分答案。至少我的一些問題與我的Razr Maxx的調試模式下的測試有關。當我通過USB調試連接時,創建新文件的調用失敗,如下所示:
06-06 10:04:30.512:W/System.err(2583):java.io.IOException:打開失敗: EACCES(拒絕) 10月6日至6日:04:305.12:W/System.err的(2583):在java.io.File.createNewFile(File.java:940)
當我運行的應用程序的獨立在我的設備或模擬器上,然後它按預期工作。不確定這是否與Razr Maxx或其他問題有關?
我的代碼工作是(來源:Write a file in external storage in Android):
private void writeToSDFile(){
// Find the root of the external storage.
// See http://developer.android.com/guide/topics/data/data- storage.html#filesExternal
File root = android.os.Environment.getExternalStorageDirectory();
mStatusTV.append("\nExternal file system root: "+root);
// See https://stackoverflow.com/questions/3551821/android-write-to-sd-card-folder
File dir = new File (root.getAbsolutePath() + "/download");
dir.mkdirs();
File file = new File(dir, "myData.txt");
try {
file.createNewFile();
FileOutputStream f = new FileOutputStream(file);
PrintWriter pw = new PrintWriter(f);
pw.println("Hi , How are you");
pw.println("Hello");
pw.flush();
pw.close();
f.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i(TAG, "******* File not found. Did you" +
" add a WRITE_EXTERNAL_STORAGE permission to the manifest?");
mStatusTV.append("Write File 1: " + e.getMessage());
} catch (IOException e) {
e.printStackTrace();
mStatusTV.append("Write File 2: " + e.getMessage());
}
mStatusTV.append("\n\nFile written to "+file);
}