Special Characters formatting in java

My program is going through files and searches and replaces blah blah, problem is, the files are written in french, therefore there are special characters in the files. and it replaces them all with a ?. how would i make java recognize all these characters?
I made it so that when it searches line by line, it outputs the old line and the new line right under. and i checked the old lines and they have ? also. so its not my code, its java. But this only happens when java interprets the line, and the code makes java interpret all the lines, changes or no changes. But it doesn't make a difference because one way or another, java has to go through every line anyways.
So I was wondering if there would be a way to make java interpret the special characters, instead of having ? everywhere. Thanks

unless im putting it at the wrong spot......its right under the try...
for (int ii = 0; ii < pathfiles.length; ii++){
        String fileName = pathfiles[ii]; //name of file
     String fileName2 = pathfiles2[ii];
        BufferedReader inFile;
        PrintWriter outFile;
        try {
         System.setProperty ("file.encoding", "ISO8859-1");
            inFile = new BufferedReader(new InputStreamReader(new FileInputStream(fileName),"UTF8"));
            outFile = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fileName2), "UTF8"));
            String fileLine;
            //First we read the file into a string called contents
            while((fileLine = inFile.readLine()) != null) {//read one line at a time
                System.out.println("old "+fileLine);
                if (fileLine.matches("(?i).*"+searchString+".*")){//if match is found replace
                    int start = fileLine.indexOf(searchString);
                    fileLine = replace(fileLine, searchString, newString);
                System.out.println("new "+fileLine);
                outFile.write(fileLine);
            inFile.close();
            outFile.close();
        catch(FileNotFoundException e) {
            System.out.println(e);
        catch(IOException e) {
            System.out.println(e);
}

Similar Messages

  • Special Characters in a Java Mapping

    Hello everybody,
    in our XI we have an Interface Mapping that uses a Java Mapping, this Mapping is doing a XSD-Validation of a XML-File.
    In one XML-File there is more than one special Character (ó, O², ü..). The XI-Parser hat no problems with these characters except one, eventhough this character (ó) exists more than once in the document, the parser doesn't recognize it in only one position (While Parsing the "ó" turns to a "��").
    I tested the Mapping in Eclipse and it works correctly. The question is, why the special character could not be interpreted in only one position in the document.
    I guess it is a bug in the XI-Parser.
    I will be thankful for your help.
    Best regards
    Adnane

    This ó has the same Hex-code as all the others and it is in the same environment.
    I definned in the source XML in the repository test the code Page in the XML-header as follows :
    <?xml version="1.0" encoding="UTF-8"?> and that works. But when I test the Process at the runtime the problem above occurs.
    I think that the interface Mapping is getting a source XML without a header, which defines the encoding as UTF-8, because when i test the Mapping in the repository with the XML-file without the Header information, the problem with the ó occurs.
    My question is, where can i define the Encoding of the source-XML of this Interface Mapping?
    regards

  • Special Characters issue in JAXB Classes generated

    Hi,
    I have generated Java bean classes from an xml schema using JAXB 2.0 Content Model feature in Jdeveloper 11g. I have another class, which has a method testMethod which takes the Java Bean class object as input. I have exposed this method as java webservice. I am just printing the FirstName from the input I have got.
    public String testMethod(TestBean testbean) {
    testBean,getContact().getFirstName();
    When there are some special characters like �, my java bean accepts and displays as �. I printed the value directly in my getter method, but it prints differently.
    How can I set my Java Bean class to use ISO-8859-1 as encoding.

    Sorry but this has nothing to do with ADF. Please try in the right forum here https://forums.oracle.com/forums/category.jspa?categoryID=285

  • Regd: Handling of special characters in XML

    Hi ALL,
    i am using java mapping to conevrt IDOC XML to Flat file using SAX parse and then reading the whole content into a single Filed,the output of the java mapping is the input for graphical mapping .
    My problem is there may be some special characters  in the input IDOC. when ever these special characters come my java mapping is not able to Parse the IDOC.
    Please let me know how can handle this special characters.
    Thanks,
    hemanth.

    Hi ,
            Java has some characters reserved which is normally used to declare the Entity Name. To handle such kind of situations, you can replace these characters with these special characters, which get substituted automatically while parsing the XML file.
    Refer:
    http://www.javacommerce.com/displaypage.jsp?name=saxparser3.sql&id=18232
    I hope it helps.
    Regards,
    Anurag Gargh
    Edited by: Anurag Gargh on Aug 11, 2009 3:41 PM

  • JAVA Mapping: Handle Special characters like u00E4,u00FC an so on

    Hi everybody,
    we have a JAVA Mapping that gerenates text nodes with special characters.
    The generated XML is later used in an graphical message-mapping.
    During runtime we ge the trace/error:
    com.sap.aii.utilxi.misc.api.BaseRuntimeException: Fatal Error:
    com.sap.engine.lib.xml.parser.ParserException: Unsupported character: 31(:main:, row:1, col:2498) at
    com.sap.aii.mappingtool.tf3.Transformer.checkParserException
    Does anybody know, how to modify the JAVA-mapping to have a workaound for this problem?
    Thanks
    Regards Mario
    Edited by: Mario Müller on Jul 22, 2008 4:33 AM

    Hi Mario,
    As java mapping does not validate the xml,the output gets created but if u have to use the xml structure,the u will have to include the following.
    Assume u r using a write method to write the output xml,then
    check for tspecial charactters like &,<,>.' etc and replce them as shown below
    private void write(String s)
         //Traverse through the string
    for (int i=0 ; i < string.length();i++)
         String s1 = data.substring(i, i + 1);
              if (s1.equals("&"))
                   write ("&amp;");
              else if (s1.equals("<"))
              write("&lt;");
              else if (s1.equals(">"))
              write("&gt;");
              else if (s1.equals("\""))
              write("&quot;");
              else if (s1.equals("'"))
              write("&apos;");
              else
              write(s1);
    Should help u out
    Edited by: Mohd Tauseef Ibrahim on Jul 22, 2008 11:08 AM
    Edited by: Mohd Tauseef Ibrahim on Jul 22, 2008 11:09 AM

  • Unable to add special characters such as # and ( in headers of Report in Text format

    Hi,
    I am working on developing a report that will be exported to tab delimited text format from SSRS. The Report has been developed and it is getting exported to tab delimited text format. However, special characters in the heading are getting trimmed. I would
    like to get these special characters in the heading of text file. Any help in this regard will be appreciated.

    Hi Abhijit,
    Per my understanding that you have add an extension which export the report as .txt format, now the issue is the special characters"#" not display after exportted, right?
    I have tested on my local environment and can reproduce the issue , this is by default, when you type some special characters "#" as the textbox name  in the properties window or as calculatted field name you will get error pop up window,
    if you type the text in the textbox as "#" it will also not display in the CSV or tab delimited text format report.
    But we have some alternative method to make them display some way, more details information below for your reference:
    Display "#" in the table header
    If we want to make them display in the table header, we need to create an new table an put all the table header as one record in the table, because the value in the table can display "#" correctly:
    I assumed you have four columns as the table header(Test1#,Test2#,Test3#,Test4#) please create an new table (HeaderTable )to store these value:
    Create two dataset2:
    Dataset1: display the record from step1
    DataSet2:display the record of the report
    Create two Tablixs as below and both remove the header column, Tablix1(Dataset1) diplay the value comes from the step1 as the new header column:
     Tablix1(Dataset2):Report Data
    In this way, when export to tab delimited txt, you will got the table header display correctly.
    Display "#" in the textbox outisde of the tablix
    If you just want to display "#" outside the tablix, you can just add an calculatted field(Test) and use expression like below to specify the value which you want to display in the calculatted field:
    ="test######test"
    Then you can use below expression in the textbox:
    =first(Fields!Test.Value, "DataSetName")
    If you still have any problem, please feel free to ask.
    Regards,
    Vicky Liu
    If you have any feedback on our support, please click
    here.
    Vicky Liu
    TechNet Community Support

  • Special characters in java, oracle and html

    Hi,
    I'm working on a mini content management system and need help with dealing with special characters.
    The input are taken from html form which are then stored into a varchar column in oracle database.
    When i retrieve the data, some of the special characters have been changed to ??? and also
    fields with double quote are modified.
    I believe there two issues;
    1. dealing with special characters
    2. display special characters back in html form textfield after retrieving.
    e.g.
    This is the line with "quote" saved to database
    This is the line with "quote" retrieved from database
    This is the line with displayed in html text field.
    Any help will be much appreciated.
    Thanks in advance.

    Maybe you should try this couple of classes: java.net.URLDecoder and java.net.URLEncoder
    Andres
    Best

  • Format Special Characters In Strings

    Is there a simple way of formatting or automatically escaping special characters in a string?
    For example if I have a string that has double quotes in it and I want to escape them, so...
    a = "This is a "string" object"becomes...
    a = "This is a \"string\" object"

    public static String escape(String s)
        String sOut;
        sOut = replace(s, "\\", "\\\\");
        sOut = replace(sOut, "'", "\\'");
        sOut = replace(sOut, "\"", "\\\"");
       sOut = replace(sOut, "\"", """);
        sOut = replace(sOut, "'", "&#039;");
        sOut = replace(sOut, ">", ">");
        sOut = replace(sOut, "<", "<");
        sOut = replace(sOut, "�", "&#xA3;");
        sOut = replace(sOut, "�", "&#xA4;");
        return (sOut);
      }Hope this helps

  • PDS - XML format, unable to read special characters in a string.

    Hi All,
    I've been using XML files to create my report with Oracle9i's new featue of PDS.
    Now, I'm unable to read a file if it contains '&' or '<' in the string. In fact, the xml file itself not able to crate a xml page in the browser, if these special characters are present.
    Is there any way to solve this problem ?
    I can't tell the users to remove &, < from the description data. Is there any way to workaround for this ?
    Thanks in advance,
    Satya.

    Hi Rohit and Rajesh
    Thanks for your reply.
    In fact, my problem is like this:
    I'll get data in .txt file and save that as a .xml file in the network before calling Oracle report ,which gets data from the .xml.
    The contents are like this:
    <Comapy name> Ford Motors UK & Europe</Company name>
    <Department> HR & Pensions</Depatrment>
    <Salary>Grad4 < 25000 </Salary>
    As per XML entity character representation, I need to replace '&' with '&amp;' and '<' with '<lt;'
    I'm wondering is there any other way to solve this problem as it is difficult to replace '<' and '>' generically.
    Honestly, I couldn't understand what Mr. Rajesh was trying to tell.
    'for & use & ( with semicolon at the end)'
    'for < use <'
    'for > use >'
    Can you shed some light on this ?
    Many thanks
    Satya.

  • Remove all the special characters using java.util.regex

    Hi,
    How to remove the all the special characters in a String[] using regex, i have the following:-
    public class RegExpTest {
         private static String removeSplCharactersForNumber(String[] number) {
              String number= null;
              Matcher m = null;
                   Pattern p = Pattern.compile("\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\+\\-\\{\\}\\|\\;\\\\\\'////\\,\\.\\?\\<\\>\\[\\]");
                   for (int i = 0; i < number.length; i++) {
                   m = p.matcher(number);
                   if (m.find()) {
                        number= m.replaceAll("");
                   System.out.println("Final Number is:::"+number);
                   return number;
              public static void main(String args[]){
                   String[] str = {"raghav!@#$%^&*()_+"};
                   RegExpTest regExpTest = new RegExpTest();
                   regExpTest.removeSplCharactersForNumber(str);
    This code is not working and m.find() is "false", here i want the output to be raghav for the entered string array, not only that it should remove all the special characters for a entered string[]. Is there a simple way to do this to remove all the special characters for a given string[]? More importantly the "spaces" (treated as a spl. character), should be removed as well. Please do provide a solution to this.
    Thanks

    You don't need the find(). Just use the replaceAll() on each element of the String[] i.e.
    String[] values = ...
    for (int i = 0; i < values.length; i++)
        values[i] = p.matcher(values).replaceAll("");
    }I can't understand your regex since the forum software has mangled it but you just need to add a space to the set of chars to remove. When you post code, surround it with CODE tags then the forum software won't mangle it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Error while handling special characters ( and &) in Sender File adapter

    Dear All,
    Scenario: Third Party System --> (File adapter) SAP PI 7.1 (SP05) --> (Proxy) ECC
    We are receiving CSV file and no mapping is required in PI as all the processing is being done by third party tool. But we are receiving special characters like ',",>,< and & in the csv file.
    When we are using File Type as TEXT and File Encoding as ISO-8859-1 than we are getting error. We changed File Type to BINARY and than we are able to handle ',",> but having issue in handling < and &.
    Any idea how we can handle it.
    Please note trhere is no Mapping in SAP PI so cannot uise Java mapping.
    Thanks a lot
    Chanakya

    Hey,
    You can add ABAP Script in Receiver Proxy for eliminating or replacing with NULL or empty. Since you dont have mapping for formatting these kind of junks you can follow the above approach.
    Else, you can remove the junks at OS level while running a small script and make it available to PI.
    Or else, you need to create mapping for sender and recevier structure though it is same, then you add a very simple UDF for fine tune.
    Use this UDF
    Here a is the input value.
    String b = "";
    b = a.replaceAll(",", "0");
    b = a.replaceAll("@", "0");
    Like all the special characters you can take and replace with zero.
    return b;
    Thanx
    Pothana

  • Runtime mapping error due to the special characters in source XML

    Hi All,
    I am facing problem with the special characters coming in the source XML message. it is failing at runtime in the mapping level. when i test with the same XML message manually in graphical message mapping it works.
    it looks like a UNICODE problem which we face noramlly in ABAP as well. but looking for a solution.
    For your reference i am giving the data which i am recivieing and the error message below.
    the problem is with the character .
    Source payload error:-
    The XML page cannot be displayed
    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
    An invalid character was found in text content. Error processing resource 'file:///C:/WINNT/profiles/CG1009/Local Settings/Temp/a173eb8_2721HTML000003'. Line 26, Position 22
    Early response is appreciated.
    Thank you

    If your message contains special chars and the encoding is not being set, then the error is of the system which is sending the message, not XI's. The webserver should return the correct encoding.
    At adapter engine, You can set the enconding for the messages you send (for example, in Soap adapter module, set XMBWS.XMLEncoding parameter with value iso-8859-1),  but not for the messages you receive.
    As a workaround, you could try using a Java Mapping to change the encoding manually. For that, set the encoding of the OutputFormat of the XML you'll serialize. Try the following code piece for the mapping (inside a try/catch declaration):
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = factory.newDocumentBuilder();
    Document input = documentBuilder.parse(in);
    OutputFormat format = new OutputFormat(XML, "ISO-8859-1", false);
    XMLSerializer serializer = new XMLSerializer(out, format);
    serializer.serialize(input);
    For that code to work, you'll need to import xercesImpl.jar and xml-apis.jar in Imported Archives of mapping objects, in Integration Repository. Both are available at http://xerces.apache.org/xerces2-j/ .
    Regards,
    Henrique.

  • Error of Special Characters in Export to Excel

    Hi,
    I guess the error you are getting is a Parser error. To solve this problem, before putting the data on the XML file, you have to pass the data through an encoding process. For UTF-8 the code for encoding should be something like.
      public java.lang.String encodeSpecialChar( java.lang.String attributeValue )
        //@@begin encodeSpecialChar()
              //Created By : AVIK SANYAL Date : 28 March 2008.
              //          Check for special characters like "&" in the String.
              //      replace "&" with "&amp;"
              //      Returns the new encoded String.
              try {
                   if (attributeValue != null) {
                        attributeValue = attributeValue.replaceAll("&", "&amp;");
                        attributeValue = attributeValue.replaceAll("<", ""&lt;"");// this is & lt
                        attributeValue = attributeValue.replaceAll(">", ""&gt;"");//this is & gt
                   } else {
              } catch (Exception ex) {
                   //          wdComponentAPI.getMessageManager().reportException(
                   //               "Failed to convert the character.",
                   //               true);
              //Returns the encoded String.
              return attributeValue;
        //@@end
    Try this and let me know if this works. The reason is that in Binary Cache method, the data is passed in an XML format and the MS-Excel application reads this to show it in the spreadsheet. The characters '&', '<' and '>' can cause failure in reading from this file.
    Thank You
    Avik
    Edited by: AVIK SANYAL on Sep 12, 2008 10:45 AM

    OK....!!!!!
    just download the Excel file (*.xls) and try open with Word-MS. In the document search by the string that you have mentioned in the question. (Use Ctrl +F).
    If you see something like "ABC bla bla ba & instead of  &amp ,  then you have to pass the data through the code I've mentioned.
    You can get more details on encoding special characters UTF-8 in Google.com or Sun Websites etc.
    You can also encode the & in hexadecimal format to get the desired output.

  • Special Characters within Email Addresses

    I am trying to send e-mails via JavaMail that contain French characters. I have no problem setting the subject and body as ISO-8859-1 compliant.
    However, there are several e-mails in the distribution list that contain special characters within the actual email (i.e. test@t�st.com). When I try to send it, I get the following error:
    javax.mail.SendFailedException: Sending failed;
      nested exception is:
            javax.mail.SendFailedException: Message partially delivered;
      nested exception is:
            javax.mail.SendFailedException: 501 badly formatted RCPT TO user <test@9
      nested exception is:
            javax.mail.SendFailedException: 501 badly formatted RCPT TO user <test@9
            at javax.mail.Transport.send0(Transport.java:219)Are there ways around this or could this be a limitation of my smtp server? If you anyone can share some info or point me towards the appropriate resources, it will be very much appreciated.
    Thanks.

    I'm pretty sure you can't put special characters in a domain name (i.e t�st.com). However, that begs the question of whether it is valid in the user name portion of the email address (i.e. t�[email protected]). I don't know for sure.
    Maybe URL encoding or Mime encoding may do something, but this is just a guess.

  • ### Problem in retrieving special characters with Oracle 9i JDBC drivers

    hi,
    We are having some problem with retrieving special characters like '�' from the database.
    Our application is using JDK1.3.1 with Oracle 9i at the back end(Version: 9.0.1.0.0). We are using oracle 9i thin drivers (classes12.zip) for database interaction.
    To relieve the data from database we are using PreparedStatement in two ways
    1. Creating a preparedstatement from connection object without any parameters and then retrieve the
    data using it. This gives the results in correct format i.e. special characters like '�'
    2. Create the preparedstatement by passing the following parameters.
    i) ResultSet.TYPE_SCROLL_INSENSITIVE
    ii) ResultSet.CONCUR_READ_ONLY
    In this case we are not able to retrieve the special character like '�' correctly. Instead the ResultSet
    returns 'h'
    I think this is the problem with Oracle drivers. Does anyone have any information about the mentioned problem.
    rgds

    I don't know exactly (because I am using JDK 1.4 with ojdbc14.jar where these problems seem to be rare...) but you may consider this:
    1. Add nls_charset12.zip to your classpath to ensure that the encoders are present (may or may not help)
    2. Swith to JDK 1.4, and do this:
    Instead of String s = getString(column)
    use
    byte[] bytes = getBytes(column);
    ByteBuffer bb = ByteBuffer.wrap(bytes); // in package java.nio
    CharBuffer cb = Charset.forname("ISO-8859-x").decode(bb);
    String s = cb.toString();
    The latter method allows you to perform the encoding/decoding manually.
    3. Change the character encoding in the database to unicode upon database setup.
    4. Try playing with NLS parameters (alter session ...)

Maybe you are looking for

  • Convert .dwg to .pdf in Acrobat X Standard

    I have Acrobat X Standard running on Windows 7.  Can I convert .dwg files to .pdf files without having AutoCAD installed?

  • Losing 1:1 previews in LR 5

    When using photoshop lightroom 5 CC on Mac OS X 10.9.5, I keep losing my 1:1 previews for NO reason (happens about once/month)... I'd like to save my previews... Help?

  • How to get the user id after login

    i am using dreamweaver cs3 authintication behaviour. i want to get the user id on session varible. not the username but the user id of the table. cheers

  • Problems with Excel 2007 and Essbase 6.5

    Hi, Two quick questions: 1. We are planning to upgrade our office to 2007, XP professional SP2 but still going to use Essbase excel add-in 6.5 for some users and Essbase 7.3 add-in for others. Has anyone faced any problems with this combination? 2. T

  • Object status tables

    Hi Please, could you tell me what is the tables where the object status are storage from SD sales document for example? Best Regards, Enrique