February 06, 2012

Writing to a file in java

How to write to Text file in java

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;


public class FileWriting {
   
    private FileOutputStream text_fos = null;
    private PrintStream textOp_psm =null;
    private  int  phoneNumber = 12345667;

    private void setFile() throws FileNotFoundException {
        text_fos = new FileOutputStream(new File("belazy.txt"));
        textOp_psm = new PrintStream(text_fos);
        textOp_psm.print("bla bla bla ............");
        textOp_psm.println(" yep yep yep ");
        textOp_psm.print("phone number is :"+phoneNumber);
        textOp_psm.println(" by belazy");
        textOp_psm.close();
       
        System.out.println(" completed ");
       
    }


   
    public static void main(String[] args) {
        FileWriting f = new FileWriting();
        try{
        f.setFile();
        }catch (Exception e) {
            // TODO: handle exception
        }
    }
}

Look here to know how to read and write an image in java blzyjava

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments