/* An example of using a text file as an input stream, and saving the results in other text file, which is the output stream instead of the screen. */ import java.util.Scanner; import java.text.DecimalFormat; import java.io.*; class TextFileEx2 { 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")); DecimalFormat myformat = new DecimalFormat("0.##"); String name; float price; price = inputFile.nextFloat(); inputFile.nextLine(); while (price != 0) { price = price + (price * RATE_OF_INFLATION); name = inputFile.nextLine(); outputFile.println(name + " -- " + myformat.format(price)); price = inputFile.nextFloat(); inputFile.nextLine(); } outputFile.close(); // outputFile must be closed at the end. } }