我正在 SD 卡上创建/保存文件。这是代码:
File sdDir = Environment.getExternalStorageDirectory();
public void btnsave_clicked(View v) throws FileNotFoundException, IOException{
File f;
f=new File(sdDir, "deposit.dma");
if(!f.exists())
f.createNewFile();
...
}
但是当我单击按钮时,它会抛出“权限被拒绝”。不要要求我添加使用权限。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
我已经在 Manifest 中添加了这个。
我该怎么办?日志信息:
10-19 20:25:14.681: E/AndroidRuntime(29016): FATAL EXCEPTION: main
10-19 20:25:14.681: E/AndroidRuntime(29016): java.lang.IllegalStateException: Could not execute method of the activity
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.view.View$1.onClick(View.java:2168)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.view.View.performClick(View.java:2552)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.view.View$PerformClick.run(View.java:9229)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.os.Handler.handleCallback(Handler.java:587)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.os.Handler.dispatchMessage(Handler.java:92)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.os.Looper.loop(Looper.java:130)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.app.ActivityThread.main(ActivityThread.java:3701)
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.lang.reflect.Method.invoke(Method.java:507)
10-19 20:25:14.681: E/AndroidRuntime(29016): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
10-19 20:25:14.681: E/AndroidRuntime(29016): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
10-19 20:25:14.681: E/AndroidRuntime(29016): at dalvik.system.NativeStart.main(Native Method)
10-19 20:25:14.681: E/AndroidRuntime(29016): Caused by: java.lang.reflect.InvocationTargetException
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.lang.reflect.Method.invoke(Method.java:507)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.view.View$1.onClick(View.java:2163)
10-19 20:25:14.681: E/AndroidRuntime(29016): ... 11 more
10-19 20:25:14.681: E/AndroidRuntime(29016): Caused by: java.io.IOException: Permission denied
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.io.File.createNewFileImpl(Native Method)
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.io.File.createNewFile(File.java:1257)
10-19 20:25:14.681: E/AndroidRuntime(29016): at org.brotheroftux.depositmaster.MainActivity.btnsave_clicked(MainActivity.java:43)
10-19 20:25:14.681: E/AndroidRuntime(29016): ... 14 more