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.
import java.util.zip.*;
public class solution {
public static void main(String args[])
{
try {
ZipFile zip_file
= new ZipFile( "f:\\file.zip" );
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.
import java.util.zip.*;
public class solution {
public static void main(String args[])
{
try {
ZipFile zip_file
= new ZipFile( "f:\\file1.zip" );
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()
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!