Translate

How to Read and Write the data in Notepad

This post helps you to Read and Write Data in Notepad. This is so simple. By using two classes FileReader, BufferedReader we can read data.





How to Read the Data
import java.io.BufferedReader;
import java.io.FileReader;
public class read_notepad {
public static void main(String[] args) throws Exception
{
FileReader fr=new FileReader(“d:\\sample1.txt”);
BufferedReader br= new BufferedReader(fr);
String x=””;
while ((x=br.readLine()) != null)
{
System.out.println(x +”\n”);
}
br.close();
}
}

How to Write the Data

Sometimes we have to print some data into Notepad according to our need.

import java.io.BufferedWriter;
import java.io.FileWriter;
public class txt_write
{
public static void main(String[] args) throws Exception
{
FileWriter fr=new FileWriter(“e:\\data.txt”);
BufferedWriter br=new BufferedWriter(fr);
br.write(“This is sample”);
br.newLine();
br.write(“Testing tools”);
br.newLine();
br.close();
}
}

No comments:

Post a Comment