DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
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, 06:04 AM
  2. Replies: 0
    Last Post: 11-20-2000, 05:37 AM
  3. Replies: 0
    Last Post: 11-20-2000, 05:32 AM
  4. Replies: 1
    Last Post: 10-11-2000, 12:23 PM
  5. Replies: 1
    Last Post: 10-06-2000, 11:25 AM

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links