Here you can find the source of getEntriesName(String jarFileName)
Parameter | Description |
---|---|
jarFileName | the jar file name |
public static String[] getEntriesName(String jarFileName) throws Exception
//package com.java2s; /*//from w ww. ja va 2 s . c o m * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Copyright (C) 2006-2010 Adele Team/LIG/Grenoble University, France */ import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class Main { /** * Util: gets the name of the entries from the given jar file name * * @param jarFileName the jar file name * @return a tabular of the entries name or null if the jar * file is empty. * @exception Exception an exception occurs */ public static String[] getEntriesName(String jarFileName) throws Exception { // Create a Jar file. JarFile jarFile = new JarFile(jarFileName); String[] tabEntriesName = null; int nbEntries = jarFile.size(); if (nbEntries > 0) { // Get all of the Jar entries. Enumeration jarEntries = jarFile.entries(); tabEntriesName = new String[nbEntries]; JarEntry currentJarEntry = null; int i = 0; while (jarEntries.hasMoreElements()) { currentJarEntry = (JarEntry) jarEntries.nextElement(); // Ajouter le nom de la nouvelle entree tabEntriesName[i] = currentJarEntry.getName(); // Incrementer l'indice i++; } } // Fermeture du fichier jar jarFile.close(); return tabEntriesName; } }