07-24 12:36:23.742:W / System.err(10386):java.io.IOException: 权限被拒绝07-24 12:36:23.750:W / System.err(10386):at java.io.File.createNewFileImpl(Native Method)07-24 12:36:23.750: W / System.err(10386):at java.io.File.createNewFile(File.java:1257) 07-24 12:36:23.750:W / System.err(10386):at com.android.SignaturePage.FileWrite(SignaturePage.java:414) 07-24 12:36:23.750:W / System.err(10386):at com.android.SignaturePage $ 2.onClick(SignaturePage.java:132) 07-24 12:36:23.750:W / System.err(10386):at android.view.View.performClick(View.java:2485)07-24 12:36:23.750: W / System.err(10386):at android.view.View $ PerformClick.run(View.java:9080)07-24 12:36:23.750: W / System.err(10386):at android.os.Handler.handleCallback(Handler.java:587)07-24 12:36:23.750:W / System.err(10386):at android.os.Handler.dispatchMessage(Handler.java:92)07-24 12:36:23.750:W / System.err(10386):at android.os.Looper.loop(Looper.java:130)07-24 12:36:23.750: W / System.err(10386):at android.app.ActivityThread.main(ActivityThread.java:3687)07-24 12:36:23.750:W / System.err(10386):at java.lang.reflect.Method.invokeNative(Native Method)07-24 12:36:23.750:W / System.err(10386):at java.lang.reflect.Method.invoke(Method.java:507)07-24 12:36:23.750: W / System.err(10386):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867) 07-24 12:36:23.750:W / System.err(10386):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)07-24 12:36:23.750:W / System.err(10386):at dalvik.system.NativeStart.main(原生方法)
我收到错误的代码段
public void FileWrite(File aPath,String aBody)
{
try
{
//System.out.println("@@@@ Inside Try FileWrite @@@@");
Log.e("BEFORE FILE","BEFORE FILE");
aPath.createNewFile();
Log.e("AFTER FILE","BEFORE AFTER");
PrintWriter out1 = new PrintWriter(aPath);
out1.write(aBody);
//System.out.println (aBody.trim());
out1.flush();
out1.close();
}
catch (IOException ioe)
{
//System.out.println("@@@@ Inside Catch FileWrite @@@@");
ioe.printStackTrace();
}
}
清单文件具有以下权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
请帮我解决问题。
aPath.createNewFile();
是发生错误的行
答案 0 :(得分:0)
File SignSave=new File("data/data/com.myapp.android.creditcardreader/SignConfirmation");
/
:File("/data/...);
编辑:
你应该将文件存储在sdcard
中。您可以通过以下方式访问sdcard
的根目录:
File root = Environment.getExternalStorageDirectory()
File aPath = new File (root, "confirmation");
aPath.createNewFile();
答案 1 :(得分:0)
将<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
添加到您的清单中,它应该有效。