How to write a Java program that reads the file "input.txt" and writes all even values from this file into a new file called "output.txt."
Sample input 10 12 1 3 5 34 2 5 7 9 44
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class FilterNumberFile { public static void main(String[] args) { File file = new File("input.txt"); try { Scanner fin = new Scanner(file); PrintWriter pw = new PrintWriter("output.txt"); int num; while (fin.hasNextInt()) { num = fin.nextInt(); if (num % 2 == 0) { pw.println(num); } } pw.close(); fin.close(); } catch (FileNotFoundException e) { System.out.println(file.getAbsolutePath() + " does not exists!"); } } }
How to write a Java program that reads the file "input.txt" and writes all even values...
Write a program that reads a file named input.txt and writes a file that contains the same contents, but is named output.txt. The input file will contain more than one line when I test this. Do not use a path name when opening these files. This means the files should be located in the top level folder of the project. Do not use a copy method that is supplied by Java. Your program must read the file line by line...
Write a C program that reads a list of positive integers from a file named "input.txt." and count number of odd integers and even integers and prints the results to another file called "results.txt". Please submit both the input and results files along with the c program.
1. use c++ write a c++ program that reads 10 integers from a file named input.txt in this file the 10 integers wil be on a single line with space between the. calculate the average of these numbers and then write his number to a file named output.txt. if the program is unable to successfully complete the file operations then display eero message to the console.
( IN JAVA): Write a program that reads each line in a file, and writes them out in reverse order into another file. This program should ask the user for the name of an input file, and the name of the output file. If the input file contains: Mary had a little lamb Its fleece was white as snow And everywhere that Mary went The lamb was sure to go Then the output file should end up containing: The lamb...
IN JAVA. Write a program that reads a file (provided as attachment to this assignment) and writes the file to a different file with line numbers inserted at the beginning of each line. For example if file input is: This is a test File output should be 1. This is a test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ BELOW FROM NOTEPAD FILE. This file contains lines of text to determine if you can properly read and write from a file.
Write a java program that reads a given data file called tickets that consists of tickets and the ticket prices. Your program should read the data and compute the find minimum, maximum and average ticket prices and output the report into a file called output.txt. The report file should look exactly (or better than) the one shown below. Your program should implement the Java ArrayList class, Java File I/O, and Java error handling exception. Below is the content of the...
C++
Write a program based on 8_lb that reads in the integer data from "input.txt" into a vector. Please prompt for the file name and append the "txt". Then create another vector where each element is the original vector times 10. Create a variable total and sum up the numbers from the second vector. The total should be 17510. Then write the data from the original vector and the 10 times vector to a file. See output.txt for the format....
Java. (20 pts) Write a program that reads all the numbers from the file mynums.dat and prints out the sum of the positive values from the file. Assume that the file contains only numeric values. You must output an error if the file can't be opened. You must write the complete program and the output when the program runs successfully must conform exactly to the sample output. Bonus ( 5 pts). Output an error if the file contains non-numeric...
Write a code that reads a line of text from standard in, and writes it to a file called "output.txt" in C please
Write a program in python that reads each line in a file, reverses its lines, and writes them to another file. For example, if the file input.txt contain the lines: Mary had a little lamb Its fleece was white as snow And everywhere that Mary went The lamb was sure to go. and you run your Python file then output.txt contains The lamb was sure to go. And everywhere that Mary went Its fleece was white as snow Mary had...