// Reading from a text file example import java.util.Scanner; import java.text.DecimalFormat; import java.io.*; class TextFileEx { public static void main(String[] args) throws IOException { Scanner inputFile; inputFile = new Scanner(new File("data.txt")); DecimalFormat myformat = new DecimalFormat("0.##"); String name; float price; price = inputFile.nextFloat(); inputFile.nextLine(); while (price != 0) { name = inputFile.nextLine(); System.out.println(name + " -- " + myformat.format(price)); price = inputFile.nextFloat(); inputFile.nextLine(); } } }