Write a program that reads in a file called input txt\' and prints out every oth
ID: 3940015 • Letter: W
Question
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.Explanation / Answer
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();
}
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.