Reading And Writing File in JAVA- Usage of File Classes FileReader,BufferedReader,FileWriter,BufferedWriter

8:31 PM 1 Comments

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ReadWriteFileEx {

/**
* @param args
*/
public static void main(String[] args)throws IOException {
// TODO Auto-generated method stub

File f = new File("myFile.txt");
System.out.println(f.getAbsolutePath());
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter("myFile1.txt");
BufferedWriter bw = new BufferedWriter(fw);

String str;
int count=0;
while((str=br.readLine())!=null)
{
System.out.println(str);
bw.write(str);
bw.write("\n");
if(str.contains("Selenium"))
{
count++;
}
}
System.out.println("No of times found String Selenium is "+ count);
  //Closing the Resources
bw.close();
fw.close();
fr.close();
br.close();
f=null;
}

}

Unknown

This site creates a platform to become an expert by gaining knowledge of unknown real-time issues as well.

1 comments:

Unknown said...

Thanks for sharing this great post here. I am looking for the solution of how to read and writing file in JAVA- Usage of File Classes FileReader,BufferedReader,FileWriter,BufferedWriter. I think this post may help all people who looks for yii framework issue. You can use Yiioverflow for more reference.