2013-07-11 4 views
0

파일에 텍스트를 쓰고 있지만 텍스트를 쓰기 전에 파일 자체를 만들 수 없습니다.파일을 만들 수 없습니다. - EACCESS 권한이 거부되었습니다.

File newxmlfile = new File(
         Environment.getExternalStorageDirectory() + "new.xml"); 
       XmlSerializer serializer = Xml.newSerializer(); 
       try { 
        newxmlfile.createNewFile(); 
       } catch (Exception e) { 
        Log.e("IOException", "exception in createNewFile() method", 
          e); 
       } 

사용 권한이 설정되었습니다.

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

SDCard도 쓰기 및 마운트 할 수 있습니다.

그러나, 나는

07-11 11:23:01.134: E/IOException(5363): exception in createNewFile() method 
07-11 11:23:01.134: E/IOException(5363): java.io.IOException: open failed: EACCES (Permission denied) 
07-11 11:23:01.134: E/IOException(5363): at java.io.File.createNewFile(File.java:948) 
07-11 11:23:01.134: E/IOException(5363): at com.app.example.MainActivity$LongOperation.doInBackground(MainActivity.java:71) 
07-11 11:23:01.134: E/IOException(5363): at com.app.example.MainActivity$LongOperation.doInBackground(MainActivity.java:1) 
07-11 11:23:01.134: E/IOException(5363): at android.os.AsyncTask$2.call(AsyncTask.java:287) 
07-11 11:23:01.134: E/IOException(5363): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
07-11 11:23:01.134: E/IOException(5363): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
07-11 11:23:01.134: E/IOException(5363): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
07-11 11:23:01.134: E/IOException(5363): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
07-11 11:23:01.134: E/IOException(5363): at java.lang.Thread.run(Thread.java:856) 
07-11 11:23:01.134: E/IOException(5363): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied) 
07-11 11:23:01.134: E/IOException(5363): at libcore.io.Posix.open(Native Method) 
07-11 11:23:01.134: E/IOException(5363): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 
07-11 11:23:01.134: E/IOException(5363): at java.io.File.createNewFile(File.java:941) 
07-11 11:23:01.134: E/IOException(5363): ... 8 more 
07-11 11:23:01.134: E/FileNotFoundException(5363): can't create FileOutputStream 
+1

' Environment.getExternalStorageDirectory() + File.Seperator + "new.xml")'Environment.getExternalStorageDirectory() + "\ new.xml" – Raghunandan

답변

2

귀하의 코드가 정확한지지고 유지, 당신은 추가해야합니다 추가 / (또는 File.separator) 파일 이름 앞에 다음과 같이이 대신

File newxmlfile = new File(
     Environment.getExternalStorageDirectory() + "/new.xml"); 
XmlSerializer serializer = Xml.newSerializer(); 
try { 
    newxmlfile.createNewFile(); 
} catch (Exception e) { 
    Log.e("IOException", "exception in createNewFile() method", 
      e); 
}