Results 1 to 2 of 2
  1. #1
    kishan.java is offline Member
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Default problem with reading a text file with special char

    Hi All,

    I have a text file with special char " ' ". Alll the fields are separated by vertical line ( I ).

    while i am reading the file i am getting error coma missing.

    To avoid the above error i am using the following code.

    public static String forXML(StringBuffer aText){
    final StringBuffer result = new StringBuffer();
    final StringCharacterIterator iterator = new StringCharacterIterator(aText.toString());
    char character = iterator.current();
    while (character != CharacterIterator.DONE ){
    if (character == '<') {
    result.append("&lt;");
    }
    else if (character == '>') {
    result.append("&gt;");
    }

    else if (character == '\"') {
    result.append("&quot;");
    }
    else if (character == '\'') {
    result.append("&apos;");
    }
    else

    if (character == '&') {
    result.append("&amp;amp;");
    }
    else if (character == '') {
    result.append("&apos;");
    }


    else {
    //the char is not a special one
    //add it to the result as is
    result.append(character);
    }
    character = iterator.next();
    }
    return result.toString();
    }


    when i called the above method in my java code. I am getting syntax error at line char character = iterator.current();

    saying that method current() is not defined for StringCharacterIterator.


    can any boady help me to solve the syntax error?

    any jar file or any import is required for the above?

    Thanks in advance.

    Regards,
    Kishan

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    I don`t understand your real problem and why do you use the StringCharacterIterator and StringBuffer, but to your question: which imports do you use?

    import java.text.CharacterIterator;
    import java.text.StringCharacterIterator;

    :confused:

Similar Threads

  1. Replies: 5
    Last Post: 03-12-2011, 01:04 AM
  2. Help reading a text file.
    By Kristoba in forum New To Java
    Replies: 5
    Last Post: 03-11-2010, 08:42 AM
  3. reading text file
    By trofyscarz in forum New To Java
    Replies: 1
    Last Post: 02-05-2010, 02:24 AM
  4. Problem with reading text from a .txt file
    By Gigi in forum New To Java
    Replies: 40
    Last Post: 01-22-2009, 03:22 AM
  5. Reading text file
    By Lennon-Guru in forum New To Java
    Replies: 1
    Last Post: 12-15-2007, 11:38 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
  •