String line;
PrintStream out = null;
BufferedReader br = null;
try {
out = new PrintStream(new FileOutputStream(outputFile));
br = new BufferedReader(new FileReader(inputFile));
while((line=br.readLine())!=null){
if(line.trim().isEmpty()) {
out.println("proc_online_system_id");
}
out.println(line);
}
} catch (IOException e) {
System.err.println(e);
} finally {
try{
out.close();
br.close();
} catch (Exception ex) {
System.err.println(ex);
}
}
And do not forget further out.close();and br.close();. This solution only stores the current line in memory, unlike the Dakkaron answer , which is correct, but you must save the entire file in memory (in an instance of StringBuilder) before writing to the file.
EDIT: after Vixen 's comment, here is the link if you have java 7 and you want to use try with resources in your solution.