2012-05-18 3 views
0

내 sdcard에 파일을 저장하려고합니다. 지금까지 제가 가지고있는 코드는 다음과 같습니다. 제공 할 수있는 도움에 정말 감사드립니다. 감사합니다 편집 : 문제는 파일이 저장되지 않는다는 것입니다. 프로그램을 종료하고 sdcard를 보면 파일이 저장되지 않았습니다. 오류 캐처에 축배를 내고 IOException이 발생하는 것 같습니다. StackTrace 로그를 확인하는 방법을 모르겠다.anddroid에서 파일을 sdcard에 저장하는 중 문제가 발생했습니다.

class bSaveListen implements Button.OnClickListener{ 
    @Override 

    public void onClick(View arg0) { 
     savef(); 
    } 

} 

public void savef(){ 
    sdCard = Environment.getExternalStorageDirectory(); 
    String filename = "aaaaaaa.txt"; 
    file = new File(sdCard, filename); 
    FileOutputStream fileout; 
    byte[] thatString = new String("awesome string").getBytes(); 
    try { 
     fileout = new FileOutputStream(file); 
     fileout.write(thatString); 
     fileout.flush(); 
     fileout.close(); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 
+0

을 좋아하지 그래서 문제가 무엇처럼해야 하는가? – neevek

+1

그래서 뭐가 문제 야? 어떤 예외? – waqaslam

+8

매니페스트에 사용 권한을 부여 했습니까? 사용 권한 android : name = "android.permission.WRITE_EXTERNAL_STORAGE"/> – Aerrow

답변

0

무엇이 잘못되었는지 알아낼 수 있어야하고 마침내 대답을했습니다. 다른 사람이 비슷한 문제를 겪고있는 경우에 대비하여 여기에 게시 할 것이라고 생각했습니다. 나는 어리석게도 그 대신에 아래 코드 대신에 코드의 응용 프로그램 블록 안에 내 허락을 썼다. 이

<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name=".Main" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name=".Main" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
</application>` 
0

아마도 예외가 발생하고 있으며, 단순히보고 있지 않습니다. 대신이 DDMS에 표시되지 않기 때문에 쓸모가 e.printStackTrace();, 사용 L.e(TAG, "Error", e); 그런 식으로 당신이 Exception을보고 내가 이것을 알아 내려고 오늘 하루 종일을 보냈다

관련 문제