Java Programing laungage

Java Input Output Projects

Java I/O Project 1

Java Input Output Examples

Java Input Output Examples

Working With Directory

There are many method is provided by the file for working the operation on the directory.

Previous Home Next

In which the first method is mkdir(). that is used for create the directory. and the second is mkdirs() method .both method is different with each other. the mkdirs method is used to create the Subdirectory of the directory.

The List() and ListFiles() method is used to list all the content of the directory. but the List() method return the an array string file name and the ListFiles() method is return an object of an array file.

Example


import java.io.File;
public class CreateDir
{
public static void main(String[] args)
{
File file = new File("C:\\Directory3");
if(file.mkdir())
{
System.out.println("Directory is created!");
}
else{
System.out.println("Failed to create directory!");
}
}
}

Random Accessing of Files

The random access file is allow to access the file with nonsequential. consider the file format is ZIP. A ZIP archive contain the file and compress it in the save space. it is contain to the directory entry at the end that indicate that the file is store in ZIP archive begin.

If we are want to extract the file from ZIP archive then we are used the sequence access stream.

you have to:

  • Firstly open the ZIP archive.
  • Search the file which you want to extract through the ZIP archive.
  • Extract the file.
  • close the ZIP archive.

By this procedure, we can not read the file before extract but if we can use the seek feature then we are read the file before extraction more efficiently. for this procedure follow the steps:

  • Open the ZIP archive.
  • Then Seek to the directory entry and locate the file which we want to extract with the ZIP archive.
  • Seek within the ZIP archive for extracted file position.
  • Extract the file which you selected.
  • at lost close the ZIP archive.

for Example of random access file goto the next page.....

Previous Home Next