Home Java Example Java Io File Handling In Java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

File Handling In Java

Advertisement
This section describes you about how to perform file handling in Java. In this section you will read what is file handling in Java, how to do file handling in Java, what is stream, file handling package, file handling classes and methods, java.io.File.

File Handling in Java

In this section we will discuss about the file handling in Java.

This section describes you about how to perform file handling in Java. In this section you will read what is file handling in Java, how to perform file handling in Java, what is stream, file handling package, file handling classes and methods, java.io.File.

What is File Handling in Java

File handling in Java means that how to read from and write to file in Java. Java provides the basic I/O package for reading and writing streams. java.io package allows to do all Input and Output tasks in Java .

Advertisement

How to perform file handling in Java

Java provides the java.io package for file handling in Java. java.io package contains the inbuilt Java classes and predefined methods using which you can read from and write data to file.

What is Stream

Stream is a sequence of data that can be of two types viz. Byte Stream and Character Stream.

Byte Stream

Byte Stream is a stream which incorporates with byte data. When an input and output process happens with byte data then it is called the file handling process with byte stream.

Character Stream

Character Stream is a stream which incorporates with characters. When an input and output process happens with character then it is called the file handling process with byte stream.

File Handling Package

Basically java.io package is used for file handling.

File Handling classes and methods

For file handling following classes and methods are useful :

Byte Stream classes are as follows :

InputStream, OutputStream, FileInputStream, FileOutputStream, ByteArrayInputStream, ByteArrayOutputStream, PrintStream, RandomAccessfile etc.

Methods defined by InputStream :

read(), read(byte[] r), available(), close(), etc.

Methods defined by OutputStream :

write(int w), write(byte[] w), finalize(), close(), etc.

Here are examples of File Handling in Java Programming Language

Character Stream classes are as follows :

Reader, Writer. These abstract classes are defined for reading and writing character streams. These classes are placed at the top of the class hierarchy.

Methods defined by Reader :

read(), read(char[] buffer), read(char[] buffer, int offset, int numChars), ready(), reset() etc.

Methods defined by Writer :

append(char ch), append(CharSequence chars), write(int ch), write(char[] buffer), write(String str), write(String str, int offset, int numChars), etc.

java.io.File

File class in java.io package contains the information about a file. An efficient and effective class for manipulating a file, or computer's file system. You can use the following methods of File for manipulating with a file.

getName(), getParent(), getParentFile(), getPath(), getAbsolutePath(), isDirectory(), isFile(), createNewFile(), delete(), mkdir(), mkdirs(), etc are the methods of File class that can be used for manipulating a file.

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 3, 2013

Ask Questions?    Discuss: File Handling In Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com