
Hi; How can I read certain line of say 10 text files and write to one text file

Java Read Multiple Files and store the data into another text file
The given code reads all the text files of the directory and stored the data into another text file.
import java.io.*;
import java.util.jar.*;
class OnlyExt implements FilenameFilter{
String ext;
public OnlyExt(String ext){
this.ext="." + ext;
}
public boolean accept(File dir,String name){
return name.endsWith(ext);
}
}
public class ReadMultipleFiles{
public static void main(String[]args) throws Exception{
BufferedWriter bw=new BufferedWriter(new FileWriter(new File("C:/output.txt")));
FilenameFilter ff = new OnlyExt("txt");
File f=new File("C:/");
File[] files = f.listFiles(ff);
for(int i=0;i<files.length;i++){
FileReader fr = new FileReader(files[i].getPath());
BufferedReader reader = new BufferedReader(fr);
String st = "";
while ((st = reader.readLine()) != null) {
bw.write(st);
bw.newLine();
}
}
bw.close();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.