0

Is there any way to store resource file(.properties) in struts 1.x in UTF-8 format. Whenever i save the file it is saved in ISO-8859 format.

Also, can i create a text file in resources folder of struts directory which will act as properties file (so that the text file can be saved in UTF-8 format), and read that file in my application to show the static text of Greek, Russian or any language.

I have read the following and try to come up with the solution but it hasn't work :

https://stackoverflow.com/a/863854/3493471

Using this my code looks like this :

import java.util.Properties;
import java.io.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class PropertiesListener {

        private static Log log = LogFactory.getLog(PropertiesListener.class);

        protected  static Properties readProperties(String name){
                Properties prop = new Properties();
                InputStream inputStream = null;
                try {
                        //inputStream = new FileInputStream(name);
                        inputStream =  EditMailboxAction.class.getResourceAsStream(name);
                        Reader reader = new InputStreamReader(inputStream, "UTF-8");
                        log.debug("Length :: "+reader.ready());
                        try {
                                prop.load(reader);
                            } catch(Exception ex){
                                 log.debug("1111111111111111111111111");
                                ex.printStackTrace();
                             }finally {
                                reader.close();
                             }
                }catch(FileNotFoundException ex){
                         log.debug("22222222222222222222");
                        ex.printStackTrace();
                  }catch(Exception ex){
                        ex.printStackTrace();
                        }
                         finally {
                  }

                return prop;
        }
}

I have called this above function to read the file using :

Properties properties = PropertiesListener.readProperties("myProperties.properties");

But it doesn't make it helpful.

As myProperties.properties isn't storing UTF-8 Charectors, I don't understand how

Reader reader = new InputStreamReader(inputStream, "UTF-8");

will help in reading UTF-8 charectors.

Community
  • 1
  • 1
vermaraj
  • 612
  • 2
  • 7
  • 33
  • "But it doesn't make it helpful" doesn't describe what you're seeing. You talk about "Whenever I save the file" - how are you saving the file? In an editor? With a Java tool? – Jon Skeet Jun 05 '14 at 09:48
  • My application runs in Linux, however to be safe , i ftp the myProperties.properties file to windows, open it in notepad++ and type the utf8 characters and save the file in Encoding UTF-8. Then i ftp the file to linux. Unfortunately when I open the file using vim in linux or even when i ftp it back to windows and again open in notepad++ it shows the output as gibberish characters. (Note: i have already changed putty settings to use utf-8) – vermaraj Jun 05 '14 at 09:55
  • That sounds like it's just a matter of using the incorrect mode in FTP. You probably want to use FTP in binary mode. Fundamentally though, if you can't transfer and edit a file appropriately, this has nothing to do with Java. – Jon Skeet Jun 05 '14 at 10:01
  • Its ok, now the application.properties file is displaying UTF8 charectors. But when it is used with struts-bean property it shows garbage charectors : For more information see this Question : http://stackoverflow.com/q/23650255/3493471 – vermaraj Jun 05 '14 at 11:45

1 Answers1

-1

Got it working. I have modified struts-config.xml and it works.

vermaraj
  • 612
  • 2
  • 7
  • 33
  • When answering your own question: you should at least provide the details of what you did. You see, as of now, the answer is pretty much useless to anybody else. So you should either delete the question completely, or put up information that really helps other, future readers. "Me solved it" doesn't help anybody. – GhostCat Dec 16 '16 at 08:03
  • 1
    How did you modify the struts-config.xml? – Chin Feb 23 '18 at 17:07