new Datei() gibt IllegalArgumentException: die Datei enthält einen Pfad-separator

Schrieb ich den folgenden code, um eine Datei zu löschen von der SD-Karte:

/**
 * Deletes a file
 * 
 * @param pathToFile
 *            Path to file, eg "/sdcard/test.txt"
 * @throws IOException
 *             Throws if file doesnt exist
 */
public static void deleteFile(String pathToFile) throws IOException {
    File file = new File(pathToFile);
    if (file.delete() == false) {
        throw new IOException();
    }
}

Jedoch, wenn ich will, um eine Datei zu löschen, die mit dieser Methode bekomme ich diesen Fehler:

E/AndroidRuntime(18085): java.lang.RuntimeException: Unable to create service de.bulling.smstalkvc_offline.InstallerService: java.lang.IllegalArgumentException: File /mnt/sdcard/voicefiles.zip contains a path separator
E/AndroidRuntime(18085):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2969)
E/AndroidRuntime(18085):    at android.app.ActivityThread.access$3300(ActivityThread.java:125)
E/AndroidRuntime(18085):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2087)
E/AndroidRuntime(18085):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(18085):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(18085):    at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(18085):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(18085):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(18085):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
E/AndroidRuntime(18085):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/AndroidRuntime(18085):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(18085): Caused by: java.lang.IllegalArgumentException: File /mnt/sdcard/voicefiles.zip contains a path separator
E/AndroidRuntime(18085):    at android.app.ContextImpl.makeFilename(ContextImpl.java:1602)
E/AndroidRuntime(18085):    at android.app.ContextImpl.deleteFile(ContextImpl.java:428)
E/AndroidRuntime(18085):    at android.content.ContextWrapper.deleteFile(ContextWrapper.java:163)
E/AndroidRuntime(18085):    at de.bulling.smstalkvc_offline.InstallerService.onCreate(InstallerService.java:30)
E/AndroidRuntime(18085):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2959)
E/AndroidRuntime(18085):    ... 10 more

Was habe ich falsch gemacht?

  • Related post:stackoverflow.com/questions/5963535/...
  • Nein, ich bin mit einem new File(), nicht ein openFileInput, so ist dies nicht die gleiche Frage.
  • Ich hab ' N sagen "doppelte Frage" aber "Verwandte". Es kann für Sie hilfreich sein zu Lesen, ähnliche Probleme. Auch hat es den Vorteil, zu erscheinen, in der Verlinkten bar in jeder Frage.
InformationsquelleAutor Force | 2011-12-12
Schreibe einen Kommentar