I have a folder with 1000 files. Each file contains text in varied number of lines. What I want and have tried to achieve is to read 'each' file and append all the lines into 1 single line (that is, I want each file to have a single line of texts).
This is what I have tried but it only prints the names of the files without effecting any changes to the files...
String line = "";
try{
    file = new FileReader(filename);
    BufferedReader reader = new BufferedReader (file);
    while ((line = reader.readLine()) != null){
        allLine.append(line);              
    }
    //System.out.println(allLine);
} catch (IOException e) {
    throw new RuntimeException("File not found");
} 
return allLine.toString();
FileWriter op = null;
op = new FileWriter(fileName);
BufferedWriter wryt = new BufferedWriter(op);
wryt.write(s);
wryt.flush();
if(op != null){
    op.close();
}
File[] lOfiles = folder.listFiles();
for (int i = 0; i< lOfiles.length; i++){
    if(lOfiles[i].isFile()){
        System.out.println(lOfiles[i].getName());
        ReadLines rd = new ReadLines();
        String rw = rd.readtxtFile(lOfiles[i].toString());
        rd.writetxtFile(lOfiles[i].getName(), rw);
    }
}
 
    