Home Java Beginners Forcing Updates to a File to the Disk



Forcing Updates to a File to the Disk
Posted on: June 7, 2007 at 12:00 AM
In this section, you will learn how to Updates to a file to the Disk in java.

Forcing Updates to a File to the Disk

     

In this program we are going to update a file forcefully. Firstly we have to make an object of OutputStream and pass a file name in which you want to update in the constructor of a FileOutputStream class. After that pass some data to the stream. The methods we are using in this class has already been discussed in other topics.

 

Code of the program is given below:

 

 

import java.io.*;

public class ForcingUpdates
{
  public static void main(String[] args
  {
  try 
  {
  // Open or create the output file
  OutputStream os = new FileOutputStream("tapan.txt");
  
  // Write some data to the stream
  byte[] data = new byte[]
  {
  (byte)124,(byte)66 };
  os.write(data);
  os.close();
  
  catch (IOException e
  {
  System.out.println("The exception has been thrown : " + e);
  }
  System.out.println("Congrats you have entered the text forcefully");
  }
}

Output is given below:

C:\ForcingUpdates>java ForcingUpdates
Congrats you have entered the text forcefully

Download this example

Related Tags for Forcing Updates to a File to the Disk:
cfileclassstlantdatedataupdateconstructorobjectmethodsstructmakemethodsedoutputstreamconstreadnameusingthisforprogramtoramssepictopeilicsputuloutputstreamfirstceinpdapasscsasforcemntouttrwanjadafterclfullpircmeobjprotorwhichssoctoreediscatkisirhallfileoutputstreamgodiscusseaandarconsstrtstreamwantupdssthavstafhatctofileoutputjeoutputsprndodsonomogro


More Tutorials from this section

Ask Questions?    Discuss: Forcing Updates to a File to the Disk   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.