Powered by Blogger.

Copying the data from one file to another file using IO Streams.

>> Friday, April 29, 2011

Copying the data from one file to another file using IO Streams_JavabynataraJ
Here the task is we have to understand  Copying the data from one file to another file.So the data should be serialized first and then by doing deserialization of same file and again serialize with different file name.



1). Write the data into a file "hello2.dat".
FileOutputStream fos = new FileOutputStream("hello2.dat");
     byte b[] = str.getBytes();
     fos.write(b);
     fos.close();

Read more..

5 ).Write a program to read a file by sending the argument as a file name at runtime.

>> Thursday, April 28, 2011

Here we are using BufferedReader to read the name of the file.

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


Read the file using FileInputStreamReader then send it to BufferedInputStreamReader to read all the data with InputStreamReader provided mehtods.



package javabynataraj.iopack;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class FileArgs {
    public static void main(String[] args)throws IOException {
        int ch;
        String fname;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter file name: ");
        fname = br.readLine();
        FileInputStream fis = new FileInputStream(fname);
        BufferedInputStream bis = new BufferedInputStream(fis);
        while((ch=bis.read())!=-1){
            System.out.print((char)ch);
        }
        fis.close();
        bis.close();

    }
}


Note:
You should have one serialized file or any file to enter the name at runtime .you should enter filename with extension like ' hello.dat '.

Read more..

4 ). Program to persist the data into a file using BufferedOutputStream

>> Wednesday, April 27, 2011

#1). Buffered classes are used to increase the performance of the application.

BufferedOutputStream working flow
#2). When ever the Buffered Classes are used by default a small amount of memory will be created with the size of 512 bytes.

#3). The data need to be written into a file, first data will be stored in the buffer then the entire data will be dumped to a file.(present with in the buffer).

#4). For each FileInputStream class there will be associated BufferedInputStream class.

String str="hi this is muralidhar";
     FileOutputStream fos=new FileOutputStream("hello.dat");


#5). These BufferedStream classes will take the other stream classes objects as an arguments.


BufferedOutputStream bos = new BufferedOutputStream(fos);


read the file and save into array of bytes  using getBytes( ) method.

and write the  object into the bos object.


package javabynataraj.iopack;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class BufferedOutput {
    public static void main(String[] args) {
        String str="hi this is muralidhar";
        try{
            FileOutputStream fos=new FileOutputStream("hello.dat");
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            byte by[] = str.getBytes();
            bos.write(by);
            bos.close();
            fos.close();
            System.out.println("Done........!");
        }
        catch(IOException ioe){
            ioe.printStackTrace();
        }
    }
}



Read more..

3). Write a program to write the data into a file by using FileOutputStream reader

By using FileOutputStream class we have to create an object by passing the argument as a file.

Then read the content in a file using getBytes[] method.


obj.getBytes[];


then by using FileOutputStreamReader class object write the data of bytes array object.

Check out the below code for this program.


package javabynataraj.iopack;

import java.io.FileOutputStream;
import java.io.IOException;

public class FileOutput {
    public static void main(String[] args) {
        String str = "Hello how are you";
        try{
            FileOutputStream fos = new FileOutputStream("stud.dat");
            byte b[] = str.getBytes();
            fos.write(b);
            fos.close();
            System.out.println("Hello World");
        }catch(IOException ioe){
            ioe.printStackTrace();
        }
    }
}


Read more..

Download Spring material from DurgaSoft

>> Saturday, April 23, 2011


Download Spring notes from Durgasoft_JavabynataraJ



Download the spring meterial from Durga soft with pdf document.

Requirements to run SPRING


SPRING runs either on Linux or Windows system. The minimum requirements for running on Windows are:
An IBM-PC compatible, at least 512 Mb RAM, processor speed 500 MHz or better

  • Hard disk: 200 MB for the software and 250 MB for examples;
  • Windows 95/98/ME/NT/XP/Vista/W7.
  • The requirements for Linux are:
  • Memory (RAM): 512Mb or more.
  • Hard disk: 200 MB free for the software and 250 Mb or more for examples.
  • Linux Operational Systems: Fedora8, Mandriva2008, OpenSuse10/11 and Ubuntu7/8

Read more..

Thread Synchronization in java (ebook download)


If a Java class has synchronized methods, each object of the class behaves like a monitor: The synchronized methods guarantee mutual exclusion of the accessing threads. A thread can wait for a condition within a synchronized method until another thread notifies the waiting thread that the condition may be fulfilled..


For more information see this

Read more..

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.