ZipFile getName() function in Java with examples
The getName()function is a part of java.util.zip package. The function returns the path name of the ZipFile object.
Function Signature:
public String getName()
Syntax:
zip_file.getName();
Parameters: The function does not require any parameters
Return value: The function returns a string, which is the path name of the zip file
Exceptions: The function does not throw any exceptions.
Below programs illustrates the use of getName() function
Example 1: Create a file named zip_file and get the name using getName() function. “file.zip” is a zip file present in f: directory.
// Java program to demonstrate the // use of getName() function import java.util.zip.*; public class solution { public static void main(String args[]) { try { // Create a Zip File ZipFile zip_file = new ZipFile("f:\\file.zip"); // Display the name of the zip file // using getName() function System.out.println(zip_file.getName()); } catch (Exception e) { System.out.println(e.getMessage()); } } } |
Output:
f:\file.zip
Example 2: Create a file named zip_file and get the name using getName() function. “file1.zip” is a non-existent zip file in f: directory.
// Java program to demonstrate the // use of getName() function import java.util.zip.*; public class solution { public static void main(String args[]) { try { // Create a Zip File ZipFile zip_file = new ZipFile("f:\\file1.zip"); // Display the name of the zip file // using getName() function System.out.println(zip_file.getName()); } catch (Exception e) { System.out.println(e.getMessage()); } } } |
Output:
f:\file1.zip (The system cannot find the file specified)
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/zip/ZipFile.html#getName()
Recommended Posts:
- ZipFile entries() function in Java with examples
- ZipFile getComment() function in Java with examples
- Java ZipFile getInputStream() function with examples
- ZipFile getEntry() function in Java with examples
- ZipFile size() function in Java with examples
- Java ZipEntry getName() function with examples
- File getName() method in Java with Examples
- Provider getName() method in Java with Examples
- Logger getName() Method in Java with Examples
- Path getName(int) method in Java with Examples
- Field getName() method in Java with Examples
- Level getName() method in Java with Examples
- Method Class | getName() Method in Java
- Java.util.function.BiPredicate interface in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



