Home » Core Java » io » File (page 3)

File

Extract a compressed zip file

This is an example of how to extract a compressed zip file. Extracting a compressed zip file implies that you should: Create a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system. Create a new ZipInputStream. Create a new FileOutputStream using a path name to the file to ...

Read More »

Rename file/directory

In this example we shall show you how to rename a File or a directory. To rename a File or a directory one should perform the following steps: Create a new File instance by converting the source pathname string into an abstract pathname. Create a new File instance by converting the target pathname string into an abstract pathname. Use the ...

Read More »

List directory contents

With this example we are going to demonstrate how to list the contents of a directory, using the list() API method of File. In short, to list all contents that a directory contains you should: Create a new File instance by converting the given pathname string into an abstract pathname. Use list() API method of File. This method returns an ...

Read More »

Get size of file in bytes

This is an example of how to get the size of a File in bytes. We are using the File class that is an abstract representation of file and directory pathnames. Getting the size of a File implies that you should: Create a new File instance by converting the given pathname string into an abstract pathname. Use the length() API ...

Read More »

Check if directory exists

In this example we shall show you how to check if a directory exists. We are using the File class that is an abstract representation of file and directory pathnames. To check if a directory exists one should perform the following steps: Create a new File instance by converting the given pathname string into an abstract pathname. Use exists() API ...

Read More »

Check if file exists

With this example we are going to demonstrate how to check if a File exists. We are using the File class that is an abstract representation of file and directory pathnames. In short, to check if a File exists you should: Create a new File instance by converting the given pathname string into an abstract pathname. Use exists() API method ...

Read More »

Delete file on JVM exit

This is an example of how to delete a File on a JVM exit. We are using the File class that is an abstract representation of file and directory pathnames. Deleting a File on a JVM exit implies that you should: Create a new File instance by converting the given pathname string into an abstract pathname. Use deleteOnExit() API method ...

Read More »

Delete file/directory

In this example we shall show you how to delete a file or directory. We are using the File class that is an abstract representation of file and directory pathnames. To delete a file or directory one should perform the following steps: Create a new File instance by converting the given pathname string into an abstract pathname. Use delete() API ...

Read More »

Create temporary file

With this example we are going to demonstrate how to create a temporary file. We are using the File class that is an abstract representation of file and directory pathnames. In short, to create a temporary file you should: Create a new File instance by converting the given pathname string into an abstract pathname. Use createTempFile(String prefix, String suffix) API ...

Read More »

Create new empty file

This is an example of how to create a new empty File. We are using the File class that is an abstract representation of file and directory pathnames. Creating a new empty file implies that you should: Create a new File instance by converting the given pathname string into an abstract pathname. Use createNewFile() API method of File. This method ...

Read More »