I?m an absolute newbe in programming java, and so I hope someone would be so kind and help me with the following question.
I want to write a java program, that reads in a line of another file and stores it in a new file. In the following source code, the file reads in a whole text from an file and stores it in another file, BUT what do I have to do if I only want to filter some words and store them?
import java.io.*; import java.util.Date;
public class readIn { public static void main(String[] args) throws IOException {
for (int i = 1; i <= 5; ++i) { System.out.println("Sleep at: " + new Date()); try {
Thread.sleep(500); } catch(InterruptedException e) { System.out.println("Sleep interrupted:"+e); } File inputFile = new File("example.txt"); File outputFile = new File("out.txt");
FileReader in = new FileReader(inputFile); FileWriter out = new FileWriter(outputFile); int c;
while ((c = in.read()) != -1) out.write(c);
in.close(); out.close();
System.out.println("Awoke at: " + new Date()); } } }