/* An example of using a text file as an input stream with an option to input additional data from the keyboard, and saving the results in a text file but at the same time printing them on the screen. */ import java.util.Scanner; import java.text.DecimalFormat; import java.io.*; class TextFileEx4 { public static void main(String[] args) throws IOException { final float RATE_OF_INFLATION = 0.025f; Scanner scan = new Scanner (System.in); String inputpath, outputpath; System.out.print ("Enter the pathname of the input file: "); inputpath = scan.nextLine(); System.out.print ("Enter the pathname of the output file: "); outputpath = scan.nextLine(); Scanner inputFile; inputFile = new Scanner(new File(inputpath)); PrintWriter outputFile; outputFile = new PrintWriter(new FileWriter(outputpath)); String name; float price; price = inputFile.nextFloat(); inputFile.nextLine(); while (price != 0) { price = price + (price * RATE_OF_INFLATION); name = inputFile.nextLine(); outputFile.println (price + " " + name); System.out.println (price + " " + name); price = inputFile.nextFloat(); inputFile.nextLine(); } inputFile.close(); outputFile.close(); } }