Reading And Writing File in JAVA- Usage of File Classes FileReader,BufferedReader,FileWriter,BufferedWriter
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;
}
}
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;
}
}