Write a program that reads in a file called input txt and pr
Write a program that reads in a file called input txt\' and prints out every other word to a file called \'output.txt\'. You will embed the input/output names for the files in the source code. You can create the input file with Notepad. The path assumed is where ever the java class code is. If using Eclipse, put the text files under the folder with the project name. A sample run: E:\\Java>type input.txt Why\'s that plane dusting crops where there ain\'t no crops? E: \\ Java> java Assignment08 E:\\Java>type output.txt Why\'s plane crops there no E:\\ Java> Notice that all I did from the command line was display the text files before and after the run. You may reference examples such as HTMLFileGenerator for using files. Do not prompt for the file name.
Solution
Answer:
import java.io.*;
public class TextProgram {
public static void main(String args[]) throws IOException {
FileReader inflow = null;
FileWriter outflow = null;
try {
inflow = new FileReader(\"input.txt\");
outflow = new FileWriter(\"output.txt\");
int flow;
while (( flow= inflow.read()) != -1) {
outflow.write(flow);
}
}finally {
if (inflow != null) {
inflow.close();
}
if (outflow != null) {
outflow.close();
}
}
}
}
