Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

file_id.diz Datei umgehen wenn ZIP geöffnet wird

Empfohlene Antworten

Veröffentlicht

Hallo,

wie kann ich die in einigen ZIP-Archiven enthaltene 'file_id.diz' Datei umgehen beim einlesen einer ZIP-Datei?

Hier mein Code zum Einlesen:

  public InputStream openFile(String name) throws Exception {

    System.out.println("File: " + name);

    InputStream result;

    try {

        result = new URL(applet.getCodeBase(),name).openStream();

        } catch(Exception e) {

        result = new FileInputStream(name);

    }

    if (name.toLowerCase().endsWith(".zip")) {

      ZipInputStream str = new ZipInputStream(result);

      str.getNextEntry();

      result = str;

    }

    return result;

}

Wer kann mir nun sagen, wie ich erkennen kann, ob eine 'file_id.diz' Datei in dem ZIP ist, und wie ich diese umgehen kann?

Beispiel:

in dem ZIP 'test.zip' sind enthalten:

- file_id.diz

- test.dsk

Nun möchte ich, dass nur das 'test.dsk' gelesen wird.

MfG

Markus

Bearbeitet von Devilmarkus

Hallo,

eine Möglichkeit wäre die folgende:

public static ArrayList<ZipEntry> readZip(String path) throws IOException {			

		ZipInputStream zis = new ZipInputStream(new FileInputStream(path));

		ZipEntry entry;

		ArrayList<ZipEntry> entries = new ArrayList<ZipEntry>();

		while((entry = zis.getNextEntry()) != null) {

			if(!entry.getName().endsWith("file_id.diz"))

				entries.add(entry);

		}


		return entries;

	}

}

ZipInputStream (Java 2 Platform SE v1.4.2)

ZipEntry (Java 2 Platform SE v1.4.2)

  • Autor
Hallo,

eine Möglichkeit wäre die folgende:

public static ArrayList<ZipEntry> readZip(String path) throws IOException {			

		ZipInputStream zis = new ZipInputStream(new FileInputStream(path));

		ZipEntry entry;

		ArrayList<ZipEntry> entries = new ArrayList<ZipEntry>();

		while((entry = zis.getNextEntry()) != null) {

			if(!entry.getName().endsWith("file_id.diz"))

				entries.add(entry);

		}


		return entries;

	}

}

ZipInputStream (Java 2 Platform SE v1.4.2)

ZipEntry (Java 2 Platform SE v1.4.2)

Klingt logisch...

Nur: Wie implementiere ich das nun in meinen Code?

ich benötige als 'result' einen java.io.InputStream.

  • Autor

Habe es herausgefunden:

   if (name.toLowerCase().endsWith(".zip")) {

          ZipEntry entry;

          ZipInputStream str = new ZipInputStream(result);

            while((entry = str.getNextEntry()) != null) {

                System.out.println("Reading " + entry.getName());

                if(!entry.getName().toLowerCase().endsWith(".diz"))

                    return str;

            }

   }

Danke für die Hilfe.

Bearbeitet von Devilmarkus

Hallo,

zum Beispiel indem du ZipFile anstatt ZipInputStream verwendest. Du bekommst so allerdings nur die erste Datei geliefert, insofern diese nicht file_id.diz heißt, ansonsten null.

public InputStream readZip(String path) throws IOException {			

		ZipFile zip = new ZipFile(path);

		ZipEntry entry;

		while(zip.entries().hasMoreElements()) {

			if(!(entry = zip.entries().nextElement()).getName().endsWith("file_id.diz"))

				return zip.getInputStream(entry);

		}


		return null;

	}

Kein Problem, vergiss nicht die Streams wieder zu schließen, ansonsten könnte es zu Problemen kommen. Am besten immer in einem finally-Block.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.