Results 1 to 13 of 13
  1. #1
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default russian character issue

    hi friends,

    i have a java code which just print russian character string to console.
    program is as below
    Java Code:
      class A
      {
      public static void main(String ... args)
      {
      System.out.print("FДКЗ CУЯILLIC GЗИЗЯДTФЯ ");
      }
      }
    but it fails on compiling.

    can anyone say whats happening in it?
    how can i use russian character in java?

    thanks in advance......

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Hi, First you have mistake in main methods. Second, You need just set special encoding for output. looks like.
    Java Code:
    public class RusOut {
        public static void main(String[] arg) {
            System.setProperty("console.encoding","Cp866");
            System.out.println("Привет из России! :)");
        }
    }
    Last edited by Petr; 04-01-2011 at 11:46 AM.
    Skype: petrarsentev
    http://TrackStudio.com

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    Quote Originally Posted by Petr View Post
    Hi, First you have mistake in main methods.
    What mistake is that?

    db

  5. #5
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Oh Sorry it's OK. This construction for main method with varargs looks strange for me. Sorry it's my mistake :)
    Skype: petrarsentev
    http://TrackStudio.com

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    Ah ok. I thought you might have spotted something I didn't.

    db

  7. #7
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    thank you all for quick reply.

    but i cant save my java file when it contains russian characters.
    i am using notepad in windows, and it ask me to save using unicode encoding.

    when i save it using unicode javac command produce much errors....

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    Notepad introduces a BOM (byte order mark) at the beginning of the file. Use a proper code editor, or open the file with a hex editor and remove the first 3 (?) characters after saving it in Notepad.

    javac command produce much errors....
    You should copy and paste those errors here, so that members trying to help don't have to guess.

    db

  9. #9
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    i have made a small change in my program.
    i saved my russian string in a txt file and tried to read it from my java code

    Java Code:
    import java.util.*;
    import java.io.*;
      
    class a
      {
    
      public static void main(String ... args)
      	{
     		System.setProperty("console.encoding","Cp866");
            	try
    		{
    			FileInputStream fr = new FileInputStream ("a.txt");
    			InputStreamReader ir= new InputStreamReader(fr , "Cp866");
    
            		BufferedReader br  = new BufferedReader (ir);
            
    
    			String line;
            		while ((line = br.readLine()) !=null)
            			{
    				System.out.println(line);
               			
            			}
    		}
    		catch (Exception e)
    		{}
    
    
      	}
      }
    but it produce

    ▼♦@♦8♦2♦5♦B♦ 8♦7♦ ♦>♦A♦A♦8♦8♦! as output

  10. #10
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    You try to set a "windows-1251" for InputStreamReader.
    Skype: petrarsentev
    http://TrackStudio.com

  11. #11
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    no change on adding ISO-8859-5

  12. #12
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    peter i tried "windows-1251" but same result

  13. #13
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,438
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by jomypgeorge View Post
    but it produce

    ▼♦@♦8♦2♦5♦B♦ 8♦7♦ ♦>♦A♦A♦8♦8♦! as output
    So your file was encoded using a different encoding. The encoding and decoding methods have to be equal of course. When I write your original example using UTF-8 everything works fine (in Eclipse, it uses UTF-8).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. How to search russian texts in Lucene index?
    By ArtUrlWWW in forum Lucene
    Replies: 0
    Last Post: 01-11-2011, 11:46 AM
  2. Replies: 0
    Last Post: 10-12-2010, 09:09 AM
  3. Replies: 23
    Last Post: 08-12-2010, 09:59 AM
  4. querying russian data from db problem
    By mr_empty in forum JDBC
    Replies: 0
    Last Post: 03-04-2008, 07:56 AM
  5. reading text character by character
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-09-2007, 08:54 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
  •