实际上我正在开发一个应用程序,当应用程序第一次运行时,它将创建一个 txt 文件,如果文件已经存在,那么它将简单地将其写入文件。
但我不知道如何以编程方式检查该文件是否存在。我试过了,
try
{
FPartyCreation = new File ("/data/data/com.MediExcel/files/","dbPartyCreation.dat");
if (FPartyCreation.exists())
{
writeOnFile();
}
else
{
FPartyCreation.createNewFile();
writeOnFile();
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
但它给出了以下错误,并且文件也没有在同一路径上创建。
07-06 01:39:26.183: E/AndroidRuntime(23107): FATAL EXCEPTION: main
07-06 01:39:26.183: E/AndroidRuntime(23107): java.lang.NullPointerException
07-06 01:39:26.183: E/AndroidRuntime(23107): at com.MediExcel.AddMethodPartyCreation.getMethod(AddMethodPartyCreation.java:28)
07-06 01:39:26.183: E/AndroidRuntime(23107): at com.MediExcel.PartyCreationActivity$1.onClick(PartyCreationActivity.java:64)
07-06 01:39:26.183: E/AndroidRuntime(23107): at android.view.View.performClick(View.java:3511)
07-06 01:39:26.183: E/AndroidRuntime(23107): at android.view.View$PerformClick.run(View.java:14105)
07-06 01:39:26.183: E/AndroidRuntime(23107): at android.os.Handler.handleCallback(Handler.java:605)
07-06 01:39:26.183: E/AndroidRuntime(23107): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 01:39:26.183: E/AndroidRuntime(23107): at android.os.Looper.loop(Looper.java:137)
07-06 01:39:26.183: E/AndroidRuntime(23107): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-06 01:39:26.183: E/AndroidRuntime(23107): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 01:39:26.183: E/AndroidRuntime(23107): at java.lang.reflect.Method.invoke(Method.java:511)
07-06 01:39:26.183: E/AndroidRuntime(23107): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-06 01:39:26.183: E/AndroidRuntime(23107): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-06 01:39:26.183: E/AndroidRuntime(23107): at dalvik.system.NativeStart.main(Native Method)
请帮我
谢谢