Java new formatted IO : format tester : Formatted IO « Language Basics « Java






Java new formatted IO : format tester

Java new formatted IO : format tester

/*
License for Java 1.5 'Tiger': A Developer's Notebook
     (O'Reilly) example package

Java 1.5 'Tiger': A Developer's Notebook (O'Reilly) 
by Brett McLaughlin and David Flanagan.
ISBN: 0-596-00738-8

You can use the examples and the source code any way you want, but
please include a reference to where it comes from if you use it in
your own products or services. Also note that this software is
provided by the author "as is", with no expressed or implied warranties. 
In no event shall the author be liable for any direct or indirect
damages arising in any way out of the use of this software.
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class FormatTester {

  public static void main(String[] args) {
    String filename = "name";

    try {
      File file = new File(filename);
      FileReader fileReader = new FileReader(file);
      BufferedReader reader = new BufferedReader(fileReader);
   
      String line;
      int i = 1;
      while ((line = reader.readLine()) != null) {
        System.out.printf("Line %d: %s%n", i++, line);
      }

    } catch (Exception e) {
      System.err.printf("Unable to open file named '%s': %s", 
                        filename, e.getMessage());
    }
  }
}

           
       








Related examples in the same category

1.Formatted Input output: A very simple example that uses Formatter.Formatted Input output: A very simple example that uses Formatter.
2.Demonstrate the format specifier.Demonstrate the format specifier.
3.Formatting time and date.
4.Demonstrate the format specifiers 2.Demonstrate the format specifiers 2.
5.Demonstrate a field-width specifier.Demonstrate a field-width specifier.
6.Java Formatter: Create a table of squares and cubes. Java Formatter: Create a table of squares and cubes.
7.Java formatted IO: the precision modifier.
8.Java formatted IO: the left justification.
9.Java formatted IO: the space format specifiers.
10.Use arguments indexes to simplify the creation of a custom time and date format.
11.Java formatted IO: Demonstrate printf().
12.Java formatted IO: Use Scanner to compute an average of the values.
13.Java formatted IO: Use Scanner to compute an average of the values in a file.
14.Use Scanner to read various types of data from a file.
15.Use Scanner to compute an average a list of comma-separated values.Use Scanner to compute an average a list of comma-separated values.
16.Java formatted IO: findInLine().