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");
        System.out.println(" completed ");

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

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

Facebook comments