/* An example of using a text file as an input stream, and saving the results in other text file and at the same time printing the results on the screen. */ import java.util.Scanner; import java.text.DecimalFormat; import java.io.*; class TextFileEx3 { public static void main(String[] args) throws IOException { final float RATE_OF_INFLATION = 0.025f; Scanner inputFile; inputFile = new Scanner(new File("data.txt")); PrintWriter outputFile; outputFile = new PrintWriter(new FileWriter("results.txt")); String name; float price; price = inputFile.nextFloat(); inputFile.nextLine(); // to accept the next String datum 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(); // to accept the next String datum } inputFile.close(); outputFile.close(); } }