converting


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: converting

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Posts
    11

    converting

    Hi,
    I've written some code (below). The program reads information from a file called “input.txt” and writes it to the terminal window. I want to the modify the program so that every full stop ‘.’ that is contained in “input.txt” is converted to an exclamation mark ‘!’ when the text is printed to the terminal window.

    import java.io.IOException;
    import java.io.FileReader;
    /**
    * Tests the result of trying to write to a file Reader.
    * Also tests the result of trying to write to a random-access file
    * that is opened only for reading.
    */

    public class OptionA
    {
    public static void main(String[] args)
    {
    try
    {
    FileReader reader = new FileReader("input.txt");
    int next;
    char c;
    boolean done = false;
    while(!done)
    {
    next = reader.read();
    if (next == -1) done = true;
    else
    {
    c = (char)next;
    System.out.print(c);
    }
    }
    reader.close();
    }
    catch (IOException exception)
    {
    System.out.println("Error in processing file: " + exception);
    }
    }
    }

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Code:
    while( (next=reader.read()) != -1)
      c = (char)next;
      System.out.print((c=='.') ? '!' : c);
    }
    eschew obfuscation

Similar Threads

  1. Converting projects to VB.NET
    By Frank Oquendo in forum .NET
    Replies: 116
    Last Post: 06-14-2002, 07:04 AM
  2. Replies: 0
    Last Post: 11-20-2000, 06:37 AM
  3. Replies: 0
    Last Post: 11-20-2000, 06:32 AM
  4. Replies: 1
    Last Post: 10-11-2000, 01:23 PM
  5. Replies: 1
    Last Post: 10-06-2000, 12:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center