2014-04-06 61 views
0

我無法調試我的一些代碼。這是一個簡單的便箋應用程序,它試圖將字符串存儲到後臺的文件中。但是,當我在平板電腦上運行應用程序時,我得到確認代碼運行的麪包,但我無法在平板電腦內部存儲器上找到該文件以證明其已存儲?保存到文件Android

我的代碼:

public void onClick(View v) { 
      //Gets the note detail from the fields. 
      noteContent = content.getText().toString(); 
      noteTitle = title.getText().toString(); 
      Date date = new Date(); 

      if (noteContent.length() == 0 || noteTitle.length() == 0) { 
       Toast.makeText(getApplicationContext(), "Please fill in both note title and content before saving", 
           Toast.LENGTH_LONG).show(); 
      } else { 

      //Adds the notes together as an object of note. 
      note createdNote = new note(noteContent, noteTitle); 
      //Adds the note to the object array. 
      noteArray.add(createdNote); 
      //Testing 
      note test = noteArray.get(0); 
      String testTitle = test.getTitle(); 
      String testContent = test.getContent(); 
      System.out.println(testTitle); 
      System.out.println(testContent); 
      //Concatenating string. 
      String noteString = testTitle + "-" + testContent; 


      try { 
       FileOutputStream FO = openFileOutput(fileName, MODE_WORLD_READABLE); 
       OutputStreamWriter osw = new OutputStreamWriter(FO); 
       try { 
        System.out.println(noteString); 
        osw.write(noteString); 
        osw.flush(); 
        osw.close(); 
        Toast.makeText(getBaseContext(), "NOTE_SAVED", Toast.LENGTH_LONG).show(); 
       } catch(IOException e) { 
        e.printStackTrace(); 
       } 
      } catch (FileNotFoundException e) { 
       e.printStackTrace(); 
      } 

我也包括權限讀/寫:■DDMS的

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

回答

0

因爲您正在寫入內部存儲器,所以您不需要權限。對於這個問題,你爲什麼要打開這樣的文件:FileOutputStream FO = openFileOutput(fileName, MODE_WORLD_READABLE);