Monday, 20 January 2014

Writing On The File Using Java

Hello Everybody today we are discuss about writing on the file by using java codes .........

Before we start writing on files:

.For Writing on the  file by java code you must know how to compile java program and little more.For this read our previous posts,  click here to see .
Now we start with coding

JAVA CODE


import java.io.*;

class write_on_file
{
public static void main (String args[])
{
File f=new File("happy.txt");
FileWriter fw=null;
try
{
fw= new FileWriter(f);
fw.write("***WELCOME TO BufferCode.in***Praveen Kumar***");
}
catch(IOException ex)
{
}
finally
{
try
{
fw.close();
}
catch(IOException exp)
{
}
}
}
}

You can use this code to handle your files using java code there you can use your file name which you wants to handle instead of happy.txt .

File f= new File("happy.txt"); is used to make object of file on which we have to write contents.

FileWriter fw=null; is used to make object of typewriter by which the writing operation have to perform.

fw.write("Anything you want to write"); is used to write on file

These are the code by which you can handle your file....

Buffercode_image1

Ouput:

buffercode_output2



Thanks for Reading post and please wait for next post in which we discribe how to more about files .

Join this site to know more about programming..