Page 1 of 2 12 LastLast
Results 1 to 20 of 24
  1. #1
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default how do java handle russian characters=unicode in Files&Streams code?

    how do java handle russian characters=unicode in Files&Streams code?

  2. #2
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    message = ( String ) input.readObject(); // when use this in textField in networking Apps Russian go to client from server without any coding additions, in case of files read/write what must do?

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    Have you looked at the Charset class? It has encoder and decoder methods to convert bytes into Unicode characters.

  4. #4
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    I don't know exactly what do you want but try to use setLocale method.

    Syntax:

    public void setLocale(java.util.Locale locale) {

    }

    Example: setLocale(new java.util.Locale("en", "US"));

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    :rolleyes:
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  6. #6
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    what is default char set in Files/Streams?

  7. #7
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    I think it is unicode.

    Do you have problem with streams or you maybe have a problem with showing text in console.

    I am using eclipse and when I want to use cyrillic characters then I go and find unicode option for text in eclipse's preferences. :cool:
    Also my small java programs with cyrillic characters don't work good, without setting that preference in eclipse.
    Last edited by cselic; 08-11-2010 at 01:58 PM.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    what is default char set in Files/Streams?
    What classes are you talking about?
    The API doc for the classes could tell you.

  9. #9
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    My code is
    Java Code:
     
    
     O n l i n e  =    A5B8
      =  
     O f f l i n e  =  5  2  A5B8
      =  
     A w a y  = 0  <5AB5
      =  
     D o   N o t   D i s t u r b  =  5  15A?>:>8BL
      =  
     N o t   A v a i l a b l e  = 
      =  
     I n v i s i b l e  =  52848<K9
      =  
     E n d   C a l l   w i t h   % s  = G8BL  @073>2>@  A  % s 
      =  
     C a l l   % s  = 8BL  % s 
      =  
     M i s s e d   c a l l  = >:
      =  
     M i s s e d   c a l l s  = :0/ >2
      =  
     I n s t a n t   m e s s a g e  =  '0B
      =  
     I n s t a n t   m e s s a g e s  =  '0BK
    
    
    public class mergerTxt 
    {
      
       private Formatter output; 
    
       public mergerTxt()
       {
          try {      {
             output = new Formatter( "merger.txt" );
             output.flush(); // flush output to send header information
             File file = new File( "us-skype.lang" ); // get file name
             File fileRu = new File( "ru-skype.lang" ); // get file name
             String result; // result from checking file
             String result2; // result from checking file
             String result3; // result from checking file
             int dot ;
    		 int dot2; 
             // file does exist
             if ( file.exists() ) 
             { 
                Scanner fileInput = new Scanner( file ); // file scanner
                Scanner fileInputRu = new Scanner( fileRu ); // file scanner
    
                while ( fileInput.hasNextLine() )
                {
                    result = fileInput.nextLine(); // read a line from file
                    result2 = fileInputRu.nextLine(); // read a line from file
                    dot = result.lastIndexOf("=");
                    dot2 = result2.lastIndexOf("=");
    	result3 = result.substring(dot + 1) + " = " + result2.substring(dot2 + 1);
    	output.format( "%s\n", result3 ); 
                } // end while
             } // end if   
    
    
    // TEXT FILES
    us-skype.lang
    sSTATUSMENU_CAPTION_ONLINE=Online
    sSTATUSMENU_CAPTION_OFFLINE=Offline
    sSTATUSMENU_CAPTION_AWAY=Away
    sSTATUSMENU_CAPTION_DND=Do Not Disturb
    sSTATUSMENU_CAPTION_NA=Not Available
    sSTATUSMENU_CAPTION_INVISIBLE=Invisible
    sREDBUTTON_HINT_HANGUP=End Call with %s
    sGREENBUTTON_HINT_CALL=Call %s
    sSTATUSPAGE_MISSEDCALLS_ONE=Missed call
    sSTATUSPAGE_MISSEDCALLS_MORE=Missed calls
    sSTATUSPAGE_MISSEDMSGS_ONE=Instant message
    sSTATUSPAGE_MISSEDMSGS_MORE=Instant messages
    ..............................................................................
    
    =============================================
    ru-skype.lang
    sSTATUSMENU_CAPTION_ONLINE=В сети
    sSTATUSMENU_CAPTION_OFFLINE=Не в сети
    sSTATUSMENU_CAPTION_AWAY=Нет на месте
    sSTATUSMENU_CAPTION_DND=Не беспокоить
    sSTATUSMENU_CAPTION_NA=Недоступен
    sSTATUSMENU_CAPTION_INVISIBLE=Невидимый
    sREDBUTTON_HINT_HANGUP=Окончить разговор с %s
    sGREENBUTTON_HINT_CALL=Позвонить %s
    sSTATUSPAGE_MISSEDCALLS_ONE=Пропущенный звонок
    sSTATUSPAGE_MISSEDCALLS_MORE=Пропущенных звонка/ов
    sSTATUSPAGE_MISSEDMSGS_ONE=Чат
    sSTATUSPAGE_MISSEDMSGS_MORE=Чаты
    ...............................................................................

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    Can you explain what the problem is?
    Show what is output and also show what you want the output to look like.

  11. #11
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    the input is the two xxxxx.lang files at the end[3306 lines each file identical but the other is in russian after equals sign in a line]. The output is the appended prior the code, and want this output appear UNDERSTANDABLE RUSSIAN words from second .lang file, so... how use char set in code in the middle above?

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

    Default

    Quote Originally Posted by lse123 View Post
    the input is the two xxxxx.lang files at the end[3306 lines each file identical but the other is in russian after equals sign in a line]. The output is the appended prior the code, and want this output appear UNDERSTANDABLE RUSSIAN words from second .lang file, so... how use char set in code in the middle above?
    If it were me I'd use InputStreamReaders and OutputStreamWriters all over the place and instantiate them with the additional parameter value "UTF-8". That way there won't be a language or character problem anywhere in the code ...

    kind regards,

    Jos

  13. #13
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    with InputStreamReaders how to read line by line the text files?

    File file = new File( "us-skype.lang" ); // get file name
    File fileRu = new File( "ru-skype.lang" ); // get file name
    File file2 = new File( "skype.lang" ); // get file name

    InputStreamReader reader = new InputStreamReader(new FileInputStream (file), "UTF-8");
    InputStreamReader readerRu = new InputStreamReader(new FileInputStream (fileRu), "UTF-8");
    OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(file2), "UTF-8");
    ..................?.................
    ..................?.................

  14. #14
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    I make another try but same result english ok russian like prior:
    Java Code:
      skype.lang
    
     O n l i n e  =    A5B8
      =  
     O f f l i n e  =  5  2  A5B8
      =  
     A w a y  = 0  <5AB5
      =  
     D o   N o t   D i s t u r b  =  5  15A?>:>8BL
      =  
     N o t   A v a i l a b l e  = 
      =  
     I n v i s i b l e  =  52848<K9
      =  
     E n d   C a l l   w i t h   % s  = G8BL  @073>2>@  A  % s 
      =  
     C a l l   % s  = 8BL  % s 
      =  
     M i s s e d   c a l l  = >:
      =  
     M i s s e d   c a l l s  = :0/ >2
      =  
     I n s t a n t   m e s s a g e  =  '0B
      =  
     I n s t a n t   m e s s a g e s  =  '0BK
      =  
     Y o u   c a n ' t   a d d   y o u r s e l f   t o   C o n t a c t s .  =  5;L7O  4>1028BL  A0<>3>  A51O
      =  
     C a l l   d u r a t i o n  = >ABL  @073>2>@0
      =  
     % s   i s   c a l l i n g  = 8B
      =  
     C o n n e c t i n g . . .  = O5<. . . 
      =  
     C a l l   i n   p r o g r e s s  =  45B  @073>2>@
      =  
     C a l l   e n d e d  = 
      =  
     N o   a n s w e r  =  5B  >B25B0
      =  
     B u s y  = OB
    
    public class mergerTxt 
    {
    
    
       public mergerTxt()
       {
          try // wait for connection, get streams, read file
          {
         
             File file = new File( "us-skype.lang" ); // get file name
             File fileRu = new File( "ru-skype.lang" ); // get file name
    		 File file2 = new File( "skype.lang" ); // get file name
    
    		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream (file), "UTF-8"));
    		BufferedReader readerRu = new BufferedReader(new InputStreamReader(new FileInputStream (fileRu), "UTF-8"));
    		OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(file2), "UTF-8"); 
    
    
             String result; // result from checking file
             String result2; // result from checking file
             String result3; // result from checking file
             int dot ;
    		 int dot2;
             int i=1;		 
             // file does exist
             if ( file.exists() ) 
             { 
    
                while ( i<3306 )
                {   //fileInput.hasNextLine()
    			i++;
                   result = reader.readLine(); // read a line from file
                   result2 = readerRu.readLine(); // read a line from file
                dot = result.lastIndexOf("=");
                dot2 = result2.lastIndexOf("=");
    		    result3 = result.substring(dot + 1) + " = " + result2.substring(dot2 + 1);
    			output.write( result3 + "\n" ); // output line of file
    
                } // end while
             } // end if
             else // file does not exist
             {
                result = file.getName() + " does not exist\n";
    
             } // end else
          } // end try
          catch( IOException ioException ) 
          {
             ioException.printStackTrace();
             System.exit( 0 );
          } // end catch
          finally
          {
             try
             {
    
             } // end try
             catch ( Exception ioException )
             {
                ioException.printStackTrace();
                System.exit( 0 );
             } // end catch
          } // end finally
       } // end method runServer
    } // end class Server

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    What is the output supposed to look like?
    There are two input files. Both in key=value format.
    The key values are both English.
    The value values are in English in the us-... file
    and in Russian in the ru-... file.

    What is the output file supposed to look like given these three different fields: English keys, English values and Russian values?

    What format are the input files in? Unicode or ASCII or ???
    On my WinXP system I had to save the ru-... file in Unicode format to preserve the Russian characters. Saved as ASCII, all the Russian letters are ???s

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    I get the following as the merged output using:
    Java Code:
    		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream (file)));
    		BufferedReader readerRu = new BufferedReader(new InputStreamReader(new FileInputStream (fileRu), "Unicode"));
    		OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(file2), "Unicode");
    Online = В сети
    Offline = Не в сети
    Away = Нет на месте
    Do Not Disturb = Не беспокоить
    Not Available = Недоступен
    Invisible = Невидимый
    End Call with %s = Окончить разговор с %s
    Call %s = Позвонить %s
    Missed call = Пропущенный звонок
    Missed calls = Пропущенных звонка/ов
    Instant message = Чат
    Instant messages = Чаты

  17. #17
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    OUTPUT:
    English values = Russian values
    English values = Russian values
    English values = Russian values
    English values = Russian values

    In Notepad++ or/and win notepad,
    how understand charset format, and how save russian char file to utf-8?

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    Did you see my post#16?

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

    Default

    Quote Originally Posted by lse123 View Post
    with InputStreamReaders how to read line by line the text files?

    File file = new File( "us-skype.lang" ); // get file name
    File fileRu = new File( "ru-skype.lang" ); // get file name
    File file2 = new File( "skype.lang" ); // get file name

    InputStreamReader reader = new InputStreamReader(new FileInputStream (file), "UTF-8");
    InputStreamReader readerRu = new InputStreamReader(new FileInputStream (fileRu), "UTF-8");
    OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(file2), "UTF-8");
    ..................?.................
    ..................?.................
    Wrap your InputStreamReader in a BufferedReader; like so:

    Java Code:
    BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")));
    kind regards,

    Jos

  20. #20
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    lse123 as I told you earlier you must go to preferences and choose utf8 for console.

    In eclipse for example is:
    Preferences -> General -> Workspace -> TextFileEncoding -> Other.
    In other choose UTF8.

    I think that your code is good with cyrillic characters but they are not visible in command line of your IDE for Java.

    This little example with russian characters works on my eclipse IDE for java:

    class Russian.java
    Java Code:
    import java.io.File;
    import java.io.FileReader;
    import java.io.BufferedReader;
    import java.io.IOException;
    
    public class Russian {
    	public static void main(String[] args) {
    			
    	
    		File filename = new File("russian.txt");
    		
    		try {
    			
    			BufferedReader in = new BufferedReader(new FileReader(filename));
    				
    			String line;
    
    			while((line = in.readLine()) != null) {
    				System.out.println(line);
    			}
    	
    		} catch(IOException ex) {
    			ex.printStackTrace();
    			System.exit(0);
    		}
    	}
    }


    file: russian.txt
    Java Code:
    Уважаемый санек, эксперементы с очисткой ленты в противном случае приводят к сокращению срока службы ленты, повреждению стыков ленты и загрязнению околоконвейерного пространства, что в итоге выражается в значительных финансовых затратах предприятия. Так что сами решайте нормально это или нет.
    
    Уважаемый Лёха-мастер, работа лопатой- это тяжелый и неблагодарный труд, который весьма дорого обходится работодателю. Нормальный межсервисный срок для очистителя составляет 6 месяцев, а срок службы- три года. Так что рекомендую обратиться к профессионалам.
    What IDE you are using? Eclipse, MotoDev, Netbeans or something else?

    You can also try to write simple program with russian characters. Try to read file with russian characters and write it to new file.
    If in new file there is also russian characters, then it is a problem with your IDE preferences.
    Last edited by cselic; 08-12-2010 at 09:13 AM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 8
    Last Post: 07-30-2010, 05:47 PM
  2. Problem with writing unicode characters in a file
    By ze snow in forum New To Java
    Replies: 1
    Last Post: 02-23-2010, 10:47 PM
  3. Replies: 2
    Last Post: 02-15-2010, 06:49 AM
  4. Form Based Authentication fails with unicode characters
    By davesquire in forum Java Servlet
    Replies: 1
    Last Post: 09-25-2009, 06:00 PM
  5. writing and reading unicode characters from a file
    By ranoosh in forum Advanced Java
    Replies: 4
    Last Post: 09-28-2008, 04:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •