Home Java Beginners fileoutputstream example
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

fileoutputstream example

Advertisement
We are going to discuss about fileoutputstream in java. The fileoutputstream class extends the java.io.FileOutputStream. It has two stream Byte and Charaters.The OutputStream abstract class use to write data to a file. The FileOutputStream is the subclass of the OutputStream abstract class.

fileoutputstream example

We are going to discuss about fileoutputstream in java. The fileoutputstream class extends the java.io.FileOutputStream. It has two stream Byte and Charaters.The OutputStream abstract class use to write data to a file. The FileOutputStream is the subclass of the OutputStream abstract class. The FileOutputStream is used to write data to a file than make the text file as a particular path in a system and we have used PrintStream class that extends the java.io.PrintStream. It writes data to another stream, you can write data like Charecter,bytes,integers,floats,String type types,

Example

package FileHandling;

import java.io.FileOutputStream;
import java.io.PrintStream;

public class FileInputStream {
	public static void main(String[] args) {
		FileOutputStream stream;
		PrintStream printStream;

		try {

			stream = new FileOutputStream("c://RoseIndia.txt");

			printStream = new PrintStream(stream);
			//create a new print stream

			printStream.println("The FileOutputStream  is used to write data to a file.");

			System.out.println("successfully created file and write ");

			printStream.close();
		} catch (Exception e) {
			System.err.println("Error writing to file");
		}
	}

}

OutPut

Download Sourse code

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 10, 2013

Ask Questions?    Discuss: fileoutputstream example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com