Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Write Text into File 
 

In this section, you will learn how to write text into a file.

 

Write Text into File

                         

In this example we are writing text into file.In this example we are initialize string to write into file. We are creating file in which we are writing string by use of write() method.

We need  java.io.*  package import first. The create   a .txt file with name "write.txt". We are using FileWriter class to read file for modification. BufferedWriter class is used for buffering the file which will store into an object of  Writer class .Then we are using write() method to write text into file. At last close output file using close() method.

The code of the program is given below:

import java.io.*;

public class WriteTextFileExample{
    public static void main(String[] args)throws IOException{
    Writer output = null;
    String text = "Rajesh Kumar";
    File file = new File("write.txt");
    output = new BufferedWriter(new FileWriter(file));
    output.write(text);
    output.close();
    System.out.println("Your file has been written");        
    }
}
 

The output of the program is given below:

C:\convert\rajesh\completed>javac WriteTextFileExample.java
C:\convert\rajesh\completed>java WriteTextFileExample
Your file has been written

Download this example.

                         

» View all related tutorials
Related Tags: c file array class list ui lists method get name using this oo root example where to exam drive store

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

5 comments so far (
post your own) View All Comments Latest 10 Comments:

This website very useful.

Posted by kannan on Monday, 04.6.09 @ 10:44am | #86532

Can help me, I want to create File to .txt from java. This File get from database record.Can you give me a solution and can give me a way and tutorial how to make txt file in java from database,please send to my email . Thank's

Posted by hendra on Wednesday, 10.15.08 @ 06:42am | #81087

I tested above program it looks good.

Posted by AnbarasanSeethapathy on Wednesday, 09.24.08 @ 11:48am | #80650

What about unicode character
What should we do for unicode character to write in file ?

Posted by omid on Wednesday, 08.8.07 @ 14:18pm | #22926

How to read a word document file and after reading, at the end of the document add something(word r sentence)?
(I'm able to read & write to doc separately but it's not my requirement),

Thanx in advance
Shashidhar S

Posted by shashidhar s on Saturday, 06.30.07 @ 11:09am | #20424

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.