Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

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..



Monday, 2 September 2013

How to implement If Statement in java tutorial

If Statement in java






Programme

import java.util.*;// we import java util package for input output

//now we make our class

class Tree
{
 public static void main(String args[])  //this is our main function
  {
  int a=30,b;
  Scanner scn=new Scanner(System.in);  //this is a class define in import java util
  System.out.println("Enter any numb");
  b=scn.nextInt(); //this is for input

  if(b==a){
  System.out.println("Wow you guess the numb");
  }
  else if(b<a)
  System.out.println("Sorry your num is less then the original");

else
System.out.println("Sorry yor num is greater than original");



  }
}