FileOutput Example

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
public class FileoutputDemo1 {
	public static void main(String args[]) {
		String str1 = null;
		String str2 = null;
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			System.out.println("Enter employee no ");
			str1 = br.readLine();
			System.out.println("Enter employee name ");
			str2 = br.readLine();
			String s = str1 + str2 + "\n";
			byte b[] = s.getBytes();
			FileOutputStream fout = new FileOutputStream("data.txt", true);
			fout.write(b);
			fout.close();
		} catch (Exception e) {
			System.out.println("error in reading text" + e);
		}
	}
}

Download

Input and Output Stream in Java

Example FileOutputStream
Example FileInputStream
DataInput and Output Example
Object Serialization
Object Deserialization
Object Externalizable Example
Example java.io.File class
RandomAccessFile Example


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code