Skip to main content

how to write text file using java


welcome java file handling tutorial .

in this tutorial we are going to wrie text file using  java here i have used Filewirter to write . use following steps to read text file using java  program
1. create one folder on d drive as f that is name of folder is f
2. create demo.txt file to write on it using program
3. create java program use following code or follow steps from video save java program in same folder import java.io.* package properly in java program
4. compile program and run
5. to understand program read what is FileReader read program explanation given below.









// Program by Prakash Sonar

import java.io.*;

class jWrite
{
public static void main(String s[])
{
try{
FileWriter w=new FileWriter("demo.txt",true);
w.write("welcome to Prakash Programming Tutorial");
w.write("\n ");
w.write("Thanks for Watching");
w.close();


}
catch(Exception e){}



}



}






 Writer, OutputStreamWriter, FileWriter and BufferedWriter


Writer is the abstract class for writing character streams. It implements the following fundamental methods:
·         write(int): writes a single character.
·         write(char[]): writes an array of characters.
·         write(String): writes a string.
·         close(): closes the stream.

OutputStreamWriter is a bridge from byte streams to character streams. Characters are encoded into bytes using a specified charset. The charset can be default character encoding of the operating system, or can be specified explicitly when creating an OutputStreamWriter.

FileWriter is a convenient class for writing text files using the default character encoding of the operating system.

BufferedWriter writes text to a character stream with efficiency (characters, arrays and strings are buffered to avoid frequently writing to the underlying stream) and provides a convenient method for writing a line 

separator: newLine().

 writer classes in the java.io package:







Comments

Labels

Show more

Popular posts from this blog

Calculator Program using jFrame

Calculator Program using jFrame java swing calculator example java jframe calculator source code java code for simple calculator using gui how to make a calculator in advance java using JFrame simple calculator program in java using frame simple calculator program in java source code write a code to create simple calculator using swing component import javax.swing.*; import java.awt.event.*; public class TextFieldExample extends JFrame implements ActionListener{     JTextField tf1,tf2,tf3;     JButton b1,b2; //declaration of control     TextFieldExample(){         JFrame f= new JFrame("Button click demo"); //         tf1=new JTextField();         tf1.setBounds(50,50,150,20);         tf2=new JTextField();         tf2.setBounds(50,100,150,20);         tf3=new JTextField();       ...

Java Program to delete record using JFrame and Prepaired Statement

Java Program to delete record using JFrame and Prepaired Statement Here is table Design  Create table demo using two column as id  and Dname , id is primary key  Program source code  +import javax.swing.*;   import java.awt.event.*;   import java.sql.*; public class FrameDelete extends JFrame implements ActionListener{       JTextField tf1,tf2,tf3;       JButton b1,b2;   JLabel l1,l2; Connection con;    PreparedStatement psmt;   int result; //declaration of control    FrameDelete(){           JFrame f= new JFrame("InsertDemo");   // l1=new JLabel("Enter RollNo"); l1.setBounds(150,10,150,50);         tf1=new JTextField();           tf1.setBounds(150,50,150,20);   tf3=new JTextField();           tf3.setBounds(1...

Basic java

java java java, learn java online free, classroom java tutorial, beginners java, java beginners, java programming,  basic java , basic java Tutorial,  basic java  Assignment           Hello friends ,       I am learning Basic java . my motive behind this blog is to help those want to learn Basic java online free of cost and grab each and every basic aspect of java programming .     you can find java tutorial from basic on this blog i will post each and every assignment of basic java with source code .          we will divide our course  in to Day work .          Let's start Day One  Basic Java Assignment for  Beginners      Basic Requirement to learn Java Programming Download following software             1. Text Editor (Notepad, Notepad++, Edit pad, Eclipse...