Results 1 to 8 of 8
  1. #1
    agajantorayev is offline Member
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default Problem with Encoding

    Hello, I am developing simple dictionary, I have problem with Encoding. I have "slovar.txt" saved in UTF-8:
    Java Code:
    Термин0 = Значение0
    Термин1 = Значение1
    Термин2 = Значение2
    Термин3 = Значение3
    Термин4 = Значение4
    Термин5 = Значение5
    Термин6 = Значение6
    Термин7 = Значение7
    Термин8 = Значение8
    Термин9 = Значение9
    and the following code:
    Java Code:
    import java.io.*;
    import java.util.*;
    
    public class NewClass {
       public static void main(String [] args) throws UnsupportedEncodingException{
           BufferedReader bf = null;
           String url = "slovar.txt";
           Map<String, String> map = new TreeMap<String, String>();
    
           String test = null;
           try{
               bf = new BufferedReader(new InputStreamReader
                       (new FileInputStream(url), "UTF-8"));
               String line = null;
               while( (line=bf.readLine())!=null ){
                   String phrase = line.substring(0, line.indexOf("="));
                   String meaning = line.substring(line.indexOf("=")+1, line.length());
                   test = phrase;
                   map.put(phrase, meaning);
               }
           }catch(Exception ex){
               ex.printStackTrace();
           }
           //now test="Термин9";
           String str = "Термин9";
           System.out.println(map.containsKey(test));// prints TRUE
           System.out.println(map.containsKey(str));// prints FALSE
       }
    }
    How it occurs? How can I fix this code in order
    Java Code:
    System.out.println(map.containsKey(str));// to print TRUE???
    to print TRUE???
    Please if anyone knows explain me

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

    Default

    that is because you have a space at the end of your key strings !
    try
    Java Code:
      String phrase = line.substring(0, line.indexOf("=") -1);
    or
    Java Code:
    map.put(phrase.trim(), meaning.trim());
    or
    Java Code:
     String str = "Термин9 ";
    :D

  3. #3
    agajantorayev is offline Member
    Join Date
    Aug 2010
    Posts
    16
    Rep Power
    0

    Default

    Thanks Eraaaaaaaaaaaaaaaaaa, I forgot about spaces, thanks a lot.

  4. #4
    Gas010 is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    hey sori but I'm having trouble with where to post my code for help so this is not a reply but anther questionimport java.util.*;
    import java.io.*;


    public class Assignment1
    {
    public static void main(String[] args)
    {

    System.out.println("I'm here");
    Scanner readFileA =null;
    Scanner readFileB =null;
    String wordSearched =null;


    String[] array=null;


    try{
    readFileA=new Scanner(new FileInputStream("FileA.in"));
    readFileB=new Scanner(new FileInputStream("FileB.in"));
    }
    catch(FileNotFoundException Fe)
    {
    System.out.println("Not Found");
    }
    int count=0;
    int position =0;
    String line = null;
    System.out.println("H");
    int i=0;
    while(readFileA.hasNextLine())
    {
    line = readFileA.nextLine();
    if(count==0)
    {
    array=new String[Integer.parseInt(line)];
    }
    else
    {
    array[i]=line;
    i++;
    }
    count++;
    }

    public int SeqSearch(String[]array,String wordSearched)
    {
    for(int j=0 ;j<array.length ;j++)

    if(WorSearched.compareTo(array[j]))
    return i;

    return -1;
    }

    }
    }

  5. #5
    Gas010 is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    this is not an answer but a question I'm having trouble with this my code.

    import java.util.*;
    import java.io.*;


    public class Assignment1
    {
    public static void main(String[] args)
    {

    System.out.println("I'm here");
    Scanner readFileA =null;
    Scanner readFileB =null;
    String wordSearched =null;


    String[] array=null;


    try{
    readFileA=new Scanner(new FileInputStream("FileA.in"));
    readFileB=new Scanner(new FileInputStream("FileB.in"));
    }
    catch(FileNotFoundException Fe)
    {
    System.out.println("Not Found");
    }
    int count=0;
    int position =0;
    String line = null;
    System.out.println("H");
    int i=0;
    while(readFileA.hasNextLine())
    {
    line = readFileA.nextLine();
    if(count==0)
    {
    array=new String[Integer.parseInt(line)];
    }
    else
    {
    array[i]=line;
    i++;
    }
    count++;
    }

    public int SeqSearch(String[]array,String wordSearched)
    {
    for(int j=0 ;j<array.length ;j++)

    if(WorSearched.compareTo(array[j]))
    return i;

    return -1;
    }

    }
    }

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

    Default

    Quote Originally Posted by Gas010 View Post
    hey sori but I'm having trouble with where to post my code for help
    search for the "New Thread" button :)

    Quote Originally Posted by Gas010 View Post
    this is not a reply but anther question
    I cant`f find the question :cool:

  7. #7
    Gas010 is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default cant find the new thread button

    hey guys i cant find the new thread button and the question I wanted ask was(check code assignment1.java),I'm basically having trouble moving on,what I'msupposed to do is to read input from one two files and compare the words to find if one file has the same words as the other file and the number of lines is indicated at the start of the file and can passed as array size plzzzzzzzzzz help:(

  8. #8
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    This thread seems to have turned into a nearly perfect pair of textbook examples of the right way and the wrong way to get help in this or any on-line forum.

    -Gary-

Similar Threads

  1. Internet Explorer + AJAX + UTF encoding problem
    By pacinpm in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 11-30-2010, 10:04 AM
  2. problem in encoding
    By jaysh in forum NetBeans
    Replies: 0
    Last Post: 08-26-2010, 09:07 AM
  3. Problem with Base64 encoding
    By Smirgu in forum Advanced Java
    Replies: 1
    Last Post: 04-15-2010, 12:05 PM
  4. Encoding Problem
    By GJ! in forum Advanced Java
    Replies: 6
    Last Post: 01-12-2010, 09:09 PM
  5. Lucene Indexer Encoding problem
    By svirid in forum Lucene
    Replies: 5
    Last Post: 02-18-2009, 10:26 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
  •